Click here to Skip to main content
15,896,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have Stored data in Temp table,and i want to use it later on so it remains save i the Database.so how long the data remains in the database

What I have tried:

I have Disconnect the Connection and Reconnect It, still i get the Data that i stored previously.
Posted
Updated 29-Jun-16 18:50pm

For SQL server a local temporary table - i.e. a table created with
SQL
CREATE TABLE #TempTableName ...
is automatically removed when the session or stored procedure ends.
So if you write it within a stored procedure, then it is cleared up and removed when the procedure exits.
Otherwise, it is destroyed when that session ends - which means when the SqlConnection is closed.

For a global temporary table - i.e. a table created with
SQL
CREATE TABLE ##TempTableName ...
it is slightly different.
In this case, it is destroyed when the session that created it and the last session referencing it ends. This is to allow multiple users access to the same temporary data.
 
Share this answer
 
Comments
Member 11605111 29-Jun-16 8:08am    
Thankful........
OriginalGriff 29-Jun-16 8:24am    
You're welcome!
A temp table is dropped when the connection that created it is closed or when the procedure that it was created in ends.

Creating and Modifying Table Basics

There are two types of temporary tables: local and global. They differ from each other in their names, their visibility, and their availability. Local temporary tables have a single number sign (#) as the first character of their names; they are visible only to the current connection for the user, and they are deleted when the user disconnects from the instance of SQL Server. Global temporary tables have two number signs (##) as the first characters of their names; they are visible to any user after they are created, and they are deleted when all users referencing the table disconnect from the instance of SQL Server.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900