22,210
社区成员
发帖
与我相关
我的任务
分享
create procedure my_proc
as
begin
select * from enterprise_account
end
go
insert into #temp
exec my_proc
create table Enterprise_Account
(id int identity(1,1) primary key, col1 varchar(5), col2 varchar(5))
insert into Enterprise_Account
select 'aa1','aa2' union all select 'bb1','bb2'
select * from Enterprise_Account
id col1 col2
----------- ----- -----
1 aa1 aa2
2 bb1 bb2
-- 复制表结构
select * into #temp from Enterprise_Account where 1=2
-- 导入数据时,排除id列: select col1,col2 from ..
insert into #temp exec('select col1,col2 from Enterprise_Account')
select * from #temp
id col1 col2
----------- ----- -----
1 aa1 aa2
2 bb1 bb2
(2 row(s) affected)
--这两句话是不一样的
--这句是把Enterprise_Account 的内容插入到#temp中并创建表,因为1=2不成立,所以出现的是空表
select * into #temp from Enterprise_Account where 1=2
--这句是插入到存在的#temp中,不会自动创建表
insert into #temp exec('select * from Enterprise_Account')