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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 What is temp table in SQL Server and Life cycle of

Author  Topic 

itnagaraj
Yak Posting Veteran

70 Posts

Posted - 2010-11-24 : 10:08:02
What is temp table in SQL Server and Life cycle of Temp Table?

Anybody kows the answer,send me



V.NAGARAJAN

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2010-11-24 : 10:18:28
Didn't this turn up yesterday?
Can't find it

It's defined starting with # for a temp table, ## for a global temp.
They are held in tempdb (with a long extension which holds a sequence number and reference to the spid) and only accessible by that spid.
Temp tables are dropped when the batch that created them ends - that is usually a stored procedure or connection (spid).
If a temp table is created on a spid then a subordinate batch creates it again another copy of the temp table will be crated with the same name - held with a different sequence number in tempdb. The temp table with the latest sequence number is always the one referenced.
A temp table can be referenced in a batch if it is created in a calling batch (e.g. an SP can use a temp table created before it runs)

Global temp tables are similar but can be accessed by any spid once they are created.
==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-11-24 : 10:35:29
http://databases.aspfaq.com/database/should-i-use-a-temp-table-or-a-table-variable.html

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

Go to Top of Page
   

- Advertisement -