Reputation: 1039
I create a global temp table (i.e ##TheTable
) using C# code. I want to be able to see that temp table in SQL server management studio after the code runs completely.
Is it possible to do this ? If yes, then how ?
Upvotes: 25
Views: 43294
Reputation: 69574
Create a test table
SELECT * INTO ##temp1
FROM dbo.SomeTable_Name
Now to check if table is there
SELECT * FROM tempdb.dbo.sysobjects O
WHERE O.xtype in ('U')
AND O.ID = OBJECT_ID(N'tempdb..##temp1')
Upvotes: 6
Reputation: 15695
After the code has finished and the session is closed, the temporary table will cease to exist. If you want to see it in SQL Server Management Studio (SSMS), you need to keep the code session open until the data has been reviewed in SSMS.
Per Technet:
Global temporary tables are visible to any user and any connection after they are created, and are deleted when all users that are referencing the table disconnect from the instance of SQL Server.
As an alternative, there's a C# code option here that selects the data from the temporary table into a code variable for review in the code ... (and if the code is to exist, you could possibly write it to a file or review by another means) -- see: https://stackoverflow.com/a/6748570/3063884
Upvotes: 9
Reputation: 2989
All temp tables are logged under SQL server > Databases > System Databases > tempdb -> Temporary Tables
Upvotes: 35