時間:2024-02-05 12:47作者:下載吧人氣:18
做數據庫開發的過程中難免會遇到有表數據備份的,而SELECT INTO……和INSERT INTO SELECT…… 這兩種語句就是用來進行表數據復制,下面簡單的介紹下:
1、INSERT INTO SELECT
語句格式:Insert Into Table2(column1,column2……) Select value1,value2,value3,value4 From Table1 或 Insert Into Table2 Select * From Table1
說明:這種方式的表復制必須要求Table2是事先創建好的
例:
–1.創建表
create TABLE Table1
(
a varchar(10),
b varchar(10),
c varchar(10)
) ;
create TABLE Table2
(
a varchar(10),
c varchar(10),
d varchar(10)
);
commit;
–2.創建測試數據
Insert into Table1 values(‘趙’,’asds’,’90’);
Insert into Table1 values(‘錢’,’asds’,’100′);
Insert into Table1 values(‘孫’,’asds’,’80’);
Insert into Table1 values(‘李’,’asds’,null);
commit;
–3.復制table1數據到table2中
Insert into Table2(a, c, d) select a,b,c from Table1;
commit;
–或,此種方式必須要求table2和table1的列數相等,而且類型兼容
Insert into Table2 select * from table1;
commit;
網友評論