Loading ...

Difference between #temp and ##temp(temporary tables) in sql server

 /5
0 (0votes)

The two types of temporary tables, local and global, 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 instances . 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 SQL Server.

Local Temporary Table

CREATE TABLE #temp

id INT, 
name VARCHAR(32) 
)

 Global Temporary Table

CREATE TABLE ##temp

id INT, 
name VARCHAR(32) 
)

 

 

A temporary table is created  in the system database tempdb. 

Local temporary table(#TEMP)  can used inside in the same scope in which it create it means if we create this inside a stored procedure then it will visible inside the stored procedure only on other hand  Global temporary table are visible out side on same connection.

Comments (no comments yet)

Top Posts