if exists(select 1 from sysobjects where name='B')
drop table b
select 100 b into b
alter table b add id int IDENTITY (1, 1) NOT NULL
select b.* from b
go
select id from b
drop table b
select 100 b into b
alter table b add id int IDENTITY (1, 1) NOT NULL
select b.* from b
go
select id from b
exec('
if exists(select 1 from sysobjects where name=''B'') drop table b
select 100 b into b
alter table b add id int IDENTITY (1, 1) NOT NULL
')
exec ('
select b.* from b
select id from b --不报错了吧?!
')
谢谢!
为什么用exec ('alter table b add id int IDENTITY (1, 1) NOT NULL
') 可以 而 exec 'alter table b add id int IDENTITY (1, 1) NOT NULL
'可以
') 不可以 而 exec 'alter table b add id int IDENTITY (1, 1) NOT NULL
'可以
为什么用exec ('alter table b add id int IDENTITY (1, 1) NOT NULL
') 可以 而 exec 'alter table b add id int IDENTITY (1, 1) NOT NULL
'不可以