, @vExecSql varchar(8000)
declare csr_GetTblName cursor
for
select NAME
from sysobjects as O
where XTYPE='U'
and Exists(select 1 from syscolumns where ID=O.ID and NAME='列名') --查询所有表中有相关列名的表
open csr_GetTblName
fetch next from csr_GetTblName into @vTblName
while @@Fetch_status = 0
begin
print @vTblName
set @vExecSql =
' if exists( select 1 from '+ @vTblName + ' as A '
+' ) '
+ ' begin '
+ ' 要操作的数据'
+ ' end '
Exec (@vExecSql)
fetch next from csr_GetTblName into @vTblName
end
close csr_GetTblName
deallocate csr_GetTblName
GO