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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Mar 18, 2015, 11:52 PM
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.
victor ebePosted Mar 18, 2015, 10:24 PM
Pankaj Kumar ChoudharyPosted Mar 18, 2015, 10:18 PM
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.