Is there a way to get a list of all current temporary tables in SQL Server?

后端 未结 5 1515
别那么骄傲
别那么骄傲 2020-12-08 12:58

I realize that temporary tables are session/connection bound and not visible or accessible out of the session/connection.

I have a long running stored procedure that

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 13:27

    SELECT left(NAME, charindex('_', NAME) - 1)
    FROM tempdb..sysobjects
    WHERE NAME LIKE '#%'
        AND NAME NOT LIKE '##%'
        AND upper(xtype) = 'U'
        AND NOT object_id('tempdb..' + NAME) IS NULL
    

    you can remove the ## line if you want to include global temp tables.

提交回复
热议问题