How to create temp table using Create statement in SQL Server?

前端 未结 2 1940
一整个雨季
一整个雨季 2021-02-05 06:46

How to create a temp table similarly to creating a normal table?

Example:

CREATE TABLE table_name 
(
    column1 datatype,
    column2 datatype,
    colu         


        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 07:02

    Same thing, Just start the table name with # or ##:

    CREATE TABLE #TemporaryTable          -- Local temporary table - starts with single #
    (
        Col1 int,
        Col2 varchar(10)
        ....
    );
    
    CREATE TABLE ##GlobalTemporaryTable   -- Global temporary table - note it starts with ##.
    (
        Col1 int,
        Col2 varchar(10)
        ....
    );
    

    Temporary table names start with # or ## - The first is a local temporary table and the last is a global temporary table.

    Here is one of many articles describing the differences between them.

提交回复
热议问题