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

前端 未结 2 1942
一整个雨季
一整个雨季 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:06

    A temporary table can have 3 kinds, the # is the most used. This is a temp table that only exists in the current session. An equivalent of this is @, a declared table variable. This has a little less "functions" (like indexes etc) and is also only used for the current session. The ## is one that is the same as the #, however, the scope is wider, so you can use it within the same session, within other stored procedures.

    You can create a temp table in various ways:

    declare @table table (id int)
    create table #table (id int)
    create table ##table (id int)
    select * into #table from xyz
    

提交回复
热议问题