時(shí)間:2024-02-05 12:47作者:下載吧人氣:20
做數(shù)據(jù)庫開發(fā)的過程中難免會遇到有表數(shù)據(jù)備份的,而SELECT INTO……和INSERT INTO SELECT…… 這兩種語句就是用來進(jìn)行表數(shù)據(jù)復(fù)制,下面簡單的介紹下:
1、INSERT INTO SELECT
語句格式:Insert Into Table2(column1,column2……) Select value1,value2,value3,value4 From Table1 或 Insert Into Table2 Select * From Table1
說明:這種方式的表復(fù)制必須要求Table2是事先創(chuàng)建好的
例:
–1.創(chuàng)建表
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.創(chuàng)建測試數(shù)據(jù)
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.復(fù)制table1數(shù)據(jù)到table2中
Insert into Table2(a, c, d) select a,b,c from Table1;
commit;
–或,此種方式必須要求table2和table1的列數(shù)相等,而且類型兼容
Insert into Table2 select * from table1;
commit;
網(wǎng)友評論