Is it possible to read data in another session's temporary table?

后端 未结 2 548
春和景丽
春和景丽 2020-12-18 00:54

We\'re maintaining (and occasionally debugging) a large in-house system. The system has 20+ databases, and a number of servers interfacing to other systems, processing data,

相关标签:
2条回答
  • 2020-12-18 01:28

    Unwieldy but you can examine the tables pages from an admin logon.

    Get object id;

    select object_id from tempdb.sys.tables where name like '#mystuff%'
    

    Get a list of allocated pages;

    dbcc ind('tempdb', <object id>, -1)
    

    for each of the PageFID / PagePID (file/page IDs)

    dbcc traceon(3604);
    dbcc page(tempdb, <PageFID>, <PagePID>, 3) with tableresults
    

    If I create #mystuff from another session I can see in a dbcc page view from my own session:

    Slot 0 Offset 0x60 Length 18    Slot 0 Column 1 Offset 0xb Length 7 Length (physical) 7 myFieldName MyValue
    
    0 讨论(0)
  • 2020-12-18 01:31

    If you prefix a temporary table name with two octothorpes, e.g. ##mystuff, it creates a global temporary table that exists outside session scope.

    That does require you to be able to alter the query text, which may or may not be accessible in this specific case.

    0 讨论(0)
提交回复
热议问题