Microsoft SQL Server

Temporary and Global Temporary Table in SQL Server

A local temporary table exists only for the duration of a connection or, if defined inside a compound statement, for the duration of the compound statement.

 CREATE TABLE #TEMPTABLE  
(
Column1 INT,
Column2 VARCHAR(30),
Column3 DATETIME DEFAULT GETDATE()
)


A global temporary
table remains in the database permanently, but the rows exist only within a given connection. When connection is closed, the data in the global temporary table disappears. However, the table definition remains with the database for access when database is opened next time.

 CREATE TABLE ##GLOBALTEMPTABLE  
(
Column1 INT,
Column2 VARCHAR(30),
Column3 DATETIME DEFAULT GETDATE()
)

Leave a comment