1. 首页>
  2. 技术文章>
  3. select into from 和 insert into select 的用法和区别

select into from 和 insert into select 的用法和区别

11/16/17 10:22:24 PM 浏览 1327 评论 0

mssql

Insert是T-sql中常用语句,但我们在开发中经常会遇到需要表复制的情况,如将一个table1的数据的部分字段复制到table2中,或者将整个table1复制到table2中,这时候我们就要使用SELECT INTO 和 INSERT INTO SELECT 表复制语句了。

如果要复制到的表不存在,则使用:

SELECT * into table2 from table1

而下面则必须保证要复制到的表存在:

Insert into Table2(field1,field2,...) select value1,value2,... from Table1

对于mysql要使用:

create table newtablename(select * from oritable)


网友讨论