GLOBAL TEMPORARY TABLE in SQL Server

The global temporary table Global Temporary Table in SQL Server (Transact-SQL) are tables created separately in SQL Server sessions,

The global temporary table Global Temporary Table in SQL Server (Transact-SQL) are tables created separately in SQL Server sessions,

Syntax

 CREAT E TABLE ##ten_bang 
(
cot1 kieudulieu [ NULL | NOT NULL ],
cot2 kieudulieu [ NULL | NOT NULL ],

);

Variable name or variable value

ten_bang

The name of the global clipboard needs to be created. The name begins with the ## character.

cot1, cot2

The column you want to create in the global clipboard. Each column must have 1 data type. The column may contain NULL or NOT NULL values. If left blank, the default is NULL.

Data types in SQL Server

Note

The name of the global clipboard is prefixed with ## (for example ## nhanvien)

For example

 CR EATE TABLE ##nhanvien 
( id_nhanvien INT PRIMARY KEY,
ho VARCHAR(50) NOT NULL,
ten VARCHAR(50),
luong MONEY
);

For this example, the CREATE TABLE command will create a global temporary table named ## name in SQL Server with 4 columns:

  1. nhanvien, INT data type, does not contain NULL value.
  2. cough, VARCHAR data type (maximum length of 50 characters) and contains no NULL value.
  3. ten, VARCHAR data type, can contain NULL values.
  4. , MONEY data type, can contain NULL values.
  5. Primary key PRIMARY KEY for table ## nhanvien is id_nhanvien.

The ## table is stored in tempdb and SQL Server will automatically delete this table when all users refer to the disconnected table from the session on SQL Server.

Previous article: VIEW in SQL Server

The following article: LOCAL TEMPORARY TABLE in SQL Server

4 ★ | 1 Vote