In this post explains how to use the GLOBAL TEMPORARY TABLES in SQL Server (Transact-SQL) with syntax and examples.
GLOBAL TEMPORARY TABLES in SQL Server (Transact-SQL) are tables that are created distinct within the SQL Server sessions.
The syntax for CREATE GLOBAL TEMPORARY TABLE in SQL Server (Transact-SQL) is:
The name of the global temporary table that you wish to create. The name of the global temporary table starts with ## characters.
The columns that you wish to create in the global temporary table. Each column must have a datatype. The column should either be defined as NULL or NOT NULL and if this value is left blank, the database assumes NULL as the default.
Let's look at an example of how to create a GLOBAL TEMPORARY TABLE in SQL Server (Transact-SQL).
For example:
This example would create a GLOBAL TEMPORARY TABLE called ##employees in SQL Server which has 4 columns.
This ##employees table is stored in tempdb and SQL Server will automatically delete this table when all users referencing the table have disconnected from the SQL Server session.