--用游标
declare @name varchar(100)
declare t_cursor cursor for
select name from sysobjects where type='U' and name!='dtproperties'open t_cursorfetch next from t_cursor into @namewhile @@fetch_status=0
begin
if not exists(select 1 from syscolumns where id=object_id(@name) and name='更新日期')
exec('alter table '+@name+' add 更新日期 datetime')
if not exists(select 1 from syscolumns where id=object_id(@name) and name='更新人')
exec('alter table '+@name+' add 更新人 varchar(20)')
...
fetch next from t_cursor into @name
endclose t_cursor
deallocate t_cursor
declare @name varchar(100)
declare t_cursor cursor for
select name from sysobjects where type='U' and name!='dtproperties'open t_cursorfetch next from t_cursor into @namewhile @@fetch_status=0
begin
if not exists(select 1 from syscolumns where id=object_id(@name) and name='更新日期')
exec('alter table '+@name+' add 更新日期 datetime')
if not exists(select 1 from syscolumns where id=object_id(@name) and name='更新人')
exec('alter table '+@name+' add 更新人 varchar(20)')
...
fetch next from t_cursor into @name
endclose t_cursor
deallocate t_cursor
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货