oracle、mysql、sybase和sqlserver復制表結構和數據


Sql Server(sybase):

1.復制表結構:

新建表student2,並且結構同表syn_xj_student一致。Sql語句如下:

select * into syn_xj_student2 from syn_xj_student where 1=2

2.復制表數據,並排除倆表中相同的數據:

insert into syn_xj_student2 select * from syn_xj_student where f_id not in (select f_id from syn_xj_student2)

mysql:

1.復制表結構:

create table topic like bbs_topic

2.復制表數據:

INSERT into topic SELECT * FROM bbs_topic

3.復制整個表:

CREATE TABLE new_table SELECT * FROM old_table;

Oracle:

1.復制表結構

create table 用戶名.表名 as select * from 用戶名.表名 where 1=2

2.同用戶表之間的數據復制

用戶B下有兩個表:B.x和B.y,如果需要從表x轉移數據到表y,使用用戶B登陸sqlpus即可:

insert into y select * from x;

3.B.x中個別字段轉移到B.y的相同字段

insert into y(字段1,字段2) select 字段1,字段2 from

4.不同用戶之間的表數據復制

對於在一個數據庫上的兩個用戶A和B,假如需要把A下表old的數據復制到B下的new,請使用權限足夠的用戶登入sqlplus:

insert into B.newTable(select * from A.oldTable);

如果需要加條件限制,比如復制當天的A.oldTable數據

insert into B.newTable(select * from A.oldTable where date=GMT);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM