Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where temp tables are located?

If I create a temporary table using # sign:

SELECT * INTO #temp FROM dbo.table

Where is this table located? I can't find this from tempdb.

like image 892
atricapilla Avatar asked Feb 03 '11 12:02

atricapilla


2 Answers

Those tables are created in your tempDB - but the table name might not be exactly as you defined.

In my case, I get:

#temp______________________________000000000003

Try this:

SELECT * INTO #temp FROM dbo.table
SELECT * FROM tempdb.sys.tables

You should see an entry for that temp table you've just created....

like image 90
marc_s Avatar answered Oct 02 '22 20:10

marc_s


When you declare a temporary table, SQL Sever adds some additional characters on its name in order to provide a unique system name for it and then it stores it in tempDB in the sysobjects table. Even though you can query the temporary table with its logical name, internally is known with the exact name SQL Server has set.

like image 26
Sachin Shanbhag Avatar answered Oct 02 '22 21:10

Sachin Shanbhag