One. Create a local temporary table in SQL
Method 1:
CREATE TABLE #本地临时表名称
Or
CREATE TABLE # #全局临时表名称
Method 2:
SELECT * into #本地临时表名称 the From table name
SELECT * into # #全局临时表名称 from table name
Description
1. The temporary table is actually a user table that is placed in tempdb.
2. The local temporary table begins with "#", and the global temporary table begins with "# #", which exists during the session and is automatically deleted at the end of the session.
Ii. deletion of temporary tables
Grammar:
DROP TABLE #本地临时表名称
Or
DROP TABLE # #全局临时表名称
Description
The drop TABLE statement explicitly drops the temporary table, or the temporary table is automatically dropped by the system when it exits its scope:
1. When the stored procedure is complete, the local temporary table created in the stored procedure is automatically dropped. This table can be referenced by all nested stored procedures that are executed by the stored procedure that created the table. However, the process calling the stored procedure that created this table cannot reference this table;
2. All other local temporary tables are automatically removed at the end of the current session ;
3. The Global temporary table is automatically dropped when the session that created the table ends and other tasks stop referencing them . The association between a task and a table is persisted only within the lifetime of a single Transact-SQL statement. In other words, when the session that created the global temporary table ends, the last Transact-SQL statement referencing this table is finished and the table is automatically dropped.
Use of SQL staging tables, local and global temporary tables