奇怪,列名无效!
--测试代码
if exists(select 1 from sysobjects where name='up_test')
drop proc up_test
GO
create proc up_test
as
select top 10 id,name into #t from sysobjects
alter table #t add test char(1) --使用动态SQL也不行
update #t
set test='1'
select * from #t
drop table #t
GO
exec up_test --执行失败
/*
(所影响的行数为 10 行)
服务器: 消息 207,级别 16,状态 1,过程 up_test,行 5
列名 'test' 无效。
*/
if exists(select 1 from sysobjects where name='up_test')
drop proc up_test
GO
create proc up_test
as
select top 10 id,name,'0' as test into #t from sysobjects --这样改就正确
--alter table #t add test char(1)
update #t
set test='1'
select * from #t
drop table #t
GO
exec up_test --执行成功
--是不是存储过程中不能alter临时表呢?但这个字段确实是加进去了.可以select出来,就是不能update.