select XXX into 和 Insert into XXX select

时间:2021-08-08 10:09:56

检索一个表中的部分行存到另一张表中。

一 、另外的那张表没有新建的时候,使用 select XXX into,创建的表与原表有相同的列名和类型:

select *
into Departments_Copy
from Departments
where Departments.ID>100

二、另外的那张表已经新建的时候,使用Insert into XXX select:

insert into Departments_Copy
select *
from Departments