天天看點

select into from 和 insert into select 的用法和差別

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