SQL Server 2014 – How to Find Ownership for a Given Temp Table

sql serversql server 2014

Is there a good way to find out which user and process owns a given user created temp table in tempdb?

Best Answer

You can use this query, courtesy of Paul White:

SELECT SUSER_NAME(CONVERT(INTEGER, OBJECTPROPERTYEX(t.OBJECT_ID, 'OwnerId')))
FROM tempdb.sys.tables AS t
WHERE t.name LIKE N'#TempTableName%';