A global temporary table is a temporary table prefixed with '##' and visible to all sessions. Global temporary tables are generally used to share data with everyone. The following is an example of a global temporary table.
-- Global temporary table if object_id ('tempdb. DBO. # globals ', 'U') is not null drop table DBO. # globals; go -- create a global temporary table create table dbo. # globals (ID int not null, value nvarchar (50) not null, constraint pk_globals primary key (ID); -- insert data into the global temporary table into DBO. # globals (ID, value) values (1, 'A'); -- query the created global temporary table select * From DBO in the current session. # globals;
Query results:
To prove that the global temporary table is visible to other sessions, we open a new query window and query with the same query statement. We will find that the query results are the same.
Global temporary table