I am a beginner to SQL Server Database. I have a basic question.
How to retrieve the column names of a temporary table
in SQL Server
?
I have tried querying the sys.objects
, but the table is not listing there.
SELECT Obj.NAME
,Col.NAME
FROM tempdb.sys.objects Obj
INNER JOIN tempdb.sys.columns Col ON Obj.object_id = Col.object_id
WHERE Obj.NAME LIKE '#tmp%'
But please note that the local temporary table names will not be unique. We can have the same names from different sessions. So be careful with the query.