insert into select與 select into from 區別 (mysql不支持 select into from )


select into from 和 insert into select 都是用來復制表

兩者的主要區別為: select into from 要求目標表不存在,因為在插入時會自動創建;insert into select from 要求目標表存在。

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


免責聲明!

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



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