Insert into select 和 select into from 区别

来源:互联网 发布:eclipse mac 图标小 编辑:程序博客网 时间:2024/04/27 22:12


SQlServer :

1.INSERT INTO SELECT语句

 语句形式为:Insert into target_table (field1,field2,...) select value1,value2,... from source_table

 要求目标表target_table 必须存在,由于目标表Table2已经存在,所以我们除了插入源表source_table的字段外,还可以插入常量。


 2.SELECT INTO FROM语句

 语句形式为:SELECT vale1, value2 into target_table from source_table

 要求目标表target_table 不存在,因为在插入时会自动创建表target_table ,并将source_table中指定字段数据复制到target_table 中。


 MySQL不支持Select Into语句直接备份表结构和数据:

 执行:SELECT * INTO sms_log_216 FROM sms_log WHERE couponid LIKE '-216%'

 出错:

 Error Code : 1327
 Undeclared variable: sms_log_216


Oracle 对于以上两个语句 target_table都必须存在 我们可以用一下语句代替

create table target_table as select  value1,value2,... from source_table


原创粉丝点击