Solved

Where Are the Temp Tables?

Posted on 2009-03-29
4
674 Views
Last Modified: 2012-05-06
I've created a temp table in SQL Server, but I can't see it anywhere in Management Studio?  Where is it?
0
Comment
Question by:NigelRocks
4 Comments
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 100 total points
ID: 24013583
it is in tempdb database.
but you might not see it there, presuming that the SSMS uses a different session that where you created the temp tables with.
0
 
LVL 1

Author Comment

by:NigelRocks
ID: 24013703
Yeah, it's not in there.
0
 
LVL 40

Assisted Solution

by:Sharath
Sharath earned 150 total points
ID: 24013913
Create a temp table as
CREATE TABLE #TempTable(Col1 int)
After creating, expand the Databases -> System Databases -> tempdb -> Temporary Tables node. You will see the temp table you have created.
Once you close the session in which you have created the temp table, you can not see you temp table in the Temporary tables list in tempdb database.
0
 
LVL 51

Accepted Solution

by:
Mark Wills earned 250 total points
ID: 24015105
as the guys above have said, temp tables are in tempdb... but only survive for the current session - they are automatically dropped.

try this little test (and maybe some handy code as well) to convince yourself. Going into SSMS and open a query window against your favourite database...

if object_id('tempdb..#test1','U') is NULL
begin
    select 'no temp test table - creating '
    create table #test1 (id int identity, column1 varchar(20))
end

insert #test1 (column1) values ('column1')     -- will insert just fine

select * from #test1

select * from tempdb.information_schema.columns where table_name like '#test1%'   -- note the 'real' table name

if object_id('tempdb..#test1','U') is NOT NULL
begin
    select 'found temp test table - dropping'
    drop table #test1                                       -- or simply finish this session
end

select * from tempdb.information_schema.columns where table_name like '#test1%'   -- not there anymore
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Complex SQL script 1 32
SQL Server can be started but not accessed 1 26
Square brackets 4 39
Rename SQL Instance/SQL Developer Edition 2012 2 12
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now