How to handle Temp Table? why i need Temp Table
Real time Example for Temp Table
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
Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted Mar 18, 2015, 6:18 PM EDT
Create Table #temp
(
Name nvarchar(50),
Age int,
Salary int
)
//Insert value in Temp table
Insert into #temp Values('Pankaj' , 20,25000)
//Retrive Data from Temp table
Select * from #temp
//Drop Temp table
Drop table #temp
Mainly we use Temp table in that scenario where we required to save some Data for future Requirement . or If there is logic inside your stored procedure which involves manipulation of data that cannot be done within a single query, then in such cases, the output of one query / intermediate results can be stored in a temporary table which then participates in further manipulation via joins etc to achieve the final result.
After execution of all query we can drop Temp. Temp table is light weight compare to Normal table in sql.
victor ebe61 reputationPosted Mar 18, 2015, 6:24 PM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 18, 2015, 7:52 PM EDT
In Below scenarios where we can use temporary tables:
•When we are doing large number of row manipulation in stored procedures.
•This is useful to replace the cursor. We can store the result set data into a temp table, then we can manipulate the data from there.
•When we are having a complex join operation.
also refer
https://www.simple-talk.com/sql/t-sql-programming/temporary-tables-in-sql-server/
hope this will help you.