select into from 和 insert into select都是用來複製表,兩者的主要區別為: select into from 要求目標表不存在,因為在插入時會自動建立。insert into select from 要求目標表存在
備份表資料: create table emp as select * from scott.emp
還原表資料:insert into emp select * from scott.emp
1. 複製表結構及其資料:
create table table_name_new as select * from table_name_old
2. 只複製表結構:
create table table_name_new as select * from table_name_old where 1=2;
或者:create table table_name_new like table_name_old
3. 只複製表資料:
如果兩個表結構一樣:
insert into table_name_new select * from table_name_old
如果兩個表結構不一樣:
insert into table_name_new(column1,column2...) select column1,column2... from table_name_old
pasting
資料庫表資料複製
同乙個資料庫中不同表之間的資料複製,比如我想將乙個資料庫demo中的table1表的資料複製到demo資料庫中表table2中 我們可以這樣寫 insert into table1 name,password money select name,password money from table2 ...
資料庫兩表複製語句
1.insert into select語句 語句形式為 insert into table2 field1,field2,select value1,value2,from table1 要求目標表table2必須存在,由於目標表table2已經存在,所以我們除了插入源表table1的字段外,還可...
mongo複製資料庫和表
1.命令 db.copydatabase fromdb,todb,fromhost,username,password,mechanism 引數解釋 fromdbt 源db todb 目標db fromhost 源db的主機位址,如果在同乙個mongod例項內可以省略 username 如果開啟了驗...