What is the Temp table in SQL Server
What is the temp table in SQL Server and where is it store ?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jun 17, 2012, 4:32 AM EDT
http://geekswithblogs.net/DevJef/archive/2011/10/08/sql-server-temp-tables.aspx
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jun 17, 2012, 4:34 AM EDT
These are similar to normal tables and can perform almost all operations as of normal table, but these tables can be created at run time.
SO for eg, if you want to save few records from a table, inside a stored proc, you can save it in temp table.
Where it is stored:
Tempdb
Types of Temp tables:
1. Local temp table:
It is available only to current connection of the user. Will be deleted automatically when user disconnects. Should start with '#' sign.
2. Global temp table:
It is available to all connections in the server. Will be deleted only if all users disconnect. Should start with '##' sign.
When to use:
1. Instead of cursors in stored proc
2. instead of complex joins in stored proc.
3. When manipulation of data cannot be used in single query.
Performance issues:
1. User should delete temporary tables when it is of no more use.
2. Temp table affects bad performances. so table variables are preferred than temp tables.
Table variable example:
Declare @TableVar Table(
User_id int,
User_Name varchar(50)
)
Satyapriya NayakRank #47 · 31.5K reputationPosted Jun 17, 2012, 5:54 AM EDT
Please refer the below links
http://www.codeproject.com/Articles/42553/Quick-Overview-Temporary-Tables-in-SQL-Server-2005
http://aartemiou.blogspot.in/2009/04/where-are-temporary-tables-stored-in.html
Thanks