Global Temp Tables

In addition to being able to create local temp tables, you can also create global temp
tables. A global temp table has global visibility, and can be seen by all connections.
Global objects are named with a double pound sign prefix, as shown in this example
where a global temp table named ##GlobalTemp is created:

CREATE TABLE ##GlobalTemp 
(
ID int NOT NULL, 
Col1 varchar(40) NULL
)

SELECT * FROM ##GlobalTemp

However, global temp tables are automatically dropped only when the connection that
created them disconnects and all other connections stop referencing them. Once the
connection that created the global temp table disconnects, connections initiated
subsequent to the closing of that connection will be unable to use the global temp
table. Connections using the global temp table that were initiated before its creator
disconnected can continue to use it.


Leave a Reply

Your email address will not be published.