首页 > 代码库 > select into 和insert into select

select into 和insert into select

select into:

  创建测试语句

create database MyDemoTest
go
use MyDemoTest
go
create table A
(
    a int primary key,
    b int,
)
go
insert into A values(1,1),
(2,2),
(3,3)

  执行核心语句:

select a,b into B from A

  执行结果:

技术分享

  由这个结果我们可以知道,B表在插入的时候并不存在

 insert into select:

 

drop table B
create table B
(
    a int primary key,
    b int,
)
go
insert into B(a,b) select a,b from A

技术分享

 

select into 和insert into select