create table select from 和 insert into table select from區別
阿新 • • 發佈:2018-12-13
create table select from
和 insert into table select from
都是用來複製表,兩者的主要區別為:
create table select from
要求目標表不存在,因為在插入時會自動建立。insert into table select from
要求目標表存在,相當於複製插入。
-
備份表資料:
create table tmp_article_info as select * from article_info
-
還原表資料:
insert into tmp_article_info select * from article_info
-
只複製表結構:
create table tmp_article_info as select * from article_info where 1=0
-
只複製表資料(如果兩個表結構完全一樣):
insert into tmp_article_info select * from article_info
-
只複製表資料(如果兩個表結構不一樣,或者部分複製):
insert into tmp_article_info (column1,column2...) select column1,column2 from article_info