Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 When do Temp tabled expire (SQL 2008R2)?

Author  Topic 

Eagle_f90
Constraint Violating Yak Guru

424 Posts

Posted - 2012-10-03 : 19:58:41
In 2008R2 if I create #Temp in a query or proc when does that table drop it's self or do I need to remember to call the drop command at the end of my work?

--
If I get used to envying others...
Those things about my self I pride will slowly fade away.
-Stellvia

sql-programmers
Posting Yak Master

190 Posts

Posted - 2012-10-04 : 00:30:20
Hi Eagle,

You dont need to drop that temp table. It will be dropped automatically when when once all connections have been closed.

Please refer this article to know about temp tables.

http://www.codeproject.com/Articles/42553/Quick-Overview-Temporary-Tables-in-SQL-Server-2005

SQL Server Programmers and Consultants
http://www.sql-programmers.com/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-10-04 : 00:37:02
quote:
Originally posted by sql-programmers

Hi Eagle,

You dont need to drop that temp table. It will be dropped automatically when when once all connections have been closed.

Please refer this article to know about temp tables.

http://www.codeproject.com/Articles/42553/Quick-Overview-Temporary-Tables-in-SQL-Server-2005

SQL Server Programmers and Consultants
http://www.sql-programmers.com/


thats for ## tables (global temporary tables)
# table gets destroyed once connection that created it terminates. Also you can have # tables with same name in multiple connections simultaneously

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-10-04 : 00:48:59
for # table, it is created inside a stored procedure, it is destroyed when the stored procedure terminates even if the connection / session is still alive.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -