--不用exec一样出错--测试
select 1 as i into #temp;alter table #temp add id int identity(1,1);select id from #temp;drop table #temp;/*--测试结果(所影响的行数为 1 行)服务器: 消息 207,级别 16,状态 3,行 8
列名 'id' 无效。
--*/
select 1 as i into #temp;alter table #temp add id int identity(1,1);select id from #temp;drop table #temp;/*--测试结果(所影响的行数为 1 行)服务器: 消息 207,级别 16,状态 3,行 8
列名 'id' 无效。
--*/
set @sql ='select 1 as i into temp;alter table temp add id int identity(1,1);select id from temp;drop table temp'
exec(@sql)
set @sql =' select 1 as i into #temp;exec(''alter table #temp add id int identity(1,1)'');select id from #temp;drop table #temp;'
exec(@sql)/*--测试结果
(所影响的行数为 1 行)
(所影响的行数为 1 行)id
-----------
1(所影响的行数为 1 行)
--*/
在add column后加go可以
可以了 ,多谢!!
to: hdhai9451(※★開拓者...脚妞伤了☆※)
这样不行
declare @sql nvarchar(1000)
set @sql =' select 1 as i into #temp;
alter table #temp add id int identity(1,1);
select * from #temp;drop table #temp;'
exec(@sql)--为什么把*改成id就不行了,怪了