Inserting data into a temporary table

后端 未结 14 1379
情书的邮戳
情书的邮戳 2020-12-22 22:28

After having created a temporary table and declaring the data types like so;

CREATE TABLE #TempTable(
ID int,
Date datetime,
Name char(20))

H

相关标签:
14条回答
  • 2020-12-22 22:59

    All the above mentioned answers will almost fullfill the purpose. However, You need to drop the temp table after all the operation on it. You can follow-

    INSERT INTO #TempTable (ID, Date, Name) 
    SELECT id, date, name 
    FROM physical_table;
    
    IF OBJECT_ID('tempdb.dbo.#TempTable') IS NOT NULL 
        DROP TABLE #TempTable;
    
    0 讨论(0)
  • 2020-12-22 23:00
    SELECT * 
    INTO #TempTable
    FROM table
    
    0 讨论(0)
提交回复
热议问题