1.select into
select into 語句把一個表中的數據插入到另一個表中。
不需要創建臨時表,在運行過程中自動創建。
基本語法:
select * into #table_Name from tableName
#table_Name 臨時表名;tableName數據源表名
2.insert into select
同樣是把一個表中的數據插入到另一個表中。
需要創建臨時表,設置字段與數據類型。
基本語法:
create table #table_Name (
column1 int,
column2 nvarchar(50),
.......
);
insert into #table_Name (column1,column2,columnn) select value1,value2,valuen from tableName
或:insert into #table_Name select * from tableName
#table_Name 臨時表名;tableName數據源表名
創建臨時表字段的順序要和查詢 tableName 表的字段順序一樣