Find ownership for a given temp table? Is there a good way to find out which user and process owns a given user created temp table in tempdb?
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%';