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,

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

May be interested

  • Install frames and temporary images on FacebookInstall frames and temporary images on Facebook
    with a temporary avatar feature on facebook, you no longer have to remember to change your avatar after holiday or anniversary instead, it will automatically do it for you.
  • PIVOT clause in SQL ServerPIVOT clause in SQL Server
    in sql server (transact-sql), the pivot clause allows cross tabulation to pass data from one table to another.
  • CLONE TABLE in SQLCLONE TABLE in SQL
    this article will show you in detail how to use clone table in sql with a specific example to make it easier to visualize and capture.
  • What is Temporary File? How to delete temporary files on windows computersWhat is Temporary File? How to delete temporary files on windows computers
    when you use the software, some temporary files are created and not deleted, filling up memory for a long time. here's how to delete temporary files on a windows computer.
  • How to create CS: GO Server on Linux VPSHow to create CS: GO Server on Linux VPS
    the official steam server game for counter-strike: global offensive is suitable for most purposes. however, you cannot control them.
  • INSERT statement in SQL ServerINSERT statement in SQL Server
    the insert statement in sql server (transact-sql) is used to insert one or more records into a table.
  • 35 tools, scripts and plugins to build HTML Table35 tools, scripts and plugins to build HTML Table
    there are many ways to visualize data, ie you can design a beautiful infographics or create interactive charts. it all depends on your data and how you want to present them.
  • Table fans and box fans, which is the smart choice?Table fans and box fans, which is the smart choice?
    electric fans are indispensable household appliances, especially on hot sunny days. in particular, box fans and table fans are cooling devices are quite a lot of users interested. however, the selection of box fans and table fans also makes many people feel puzzled by the similarities of utility and price.
  • DELETE command in SQL ServerDELETE command in SQL Server
    the delete statement in sql server (transact-sql) is used to delete one or more records from a table in sql server.
  • Free up space on Windows 10 by deleting temporary filesFree up space on Windows 10 by deleting temporary files
    each time you create a file or application, there are usually temporary files (temporary files), but they only work at the current time. thus, when not in use, these temporary files will take up your computer space. so how to automatically delete them? let's find out more details in the article!