How to create a temporary table in SQL Server?
In SQL Server, you can use the CREATE TABLE statement to create temporary tables. Temporary tables are automatically dropped when the current session ends. Here is the basic syntax for creating a temporary table:
CREATE TABLE #临时表名 (列1 数据类型,
列2 数据类型,
...
)
Here, #temporary_table_name is the name of the temporary table, which can be customized. Next, list the columns to be included in the table and specify the data type for each column. Here is an example:
CREATE TABLE #Temp (ID INT,
Name VARCHAR(50),
Age INT
)
The statement above will create a temporary table named #Temp with three columns: ID, Name, and Age. It is important to note that the name of the temporary table must start with # in order to distinguish it from permanent tables.