--- /* 以下是遍历一个数据库的 */ use db declare @sql varchar(500) declare @tablename varchar(20) declare test1 cursor for select name from sysobjects where xtype='U' open test1 fetch next from test1 into @tablename while @@FETCH_STATUS=0 begin select @sql='select * from '+@tablename +' where name ='+'''李智''' print @sql begin try print @sql exec(@sql) end try begin catch print 'error' end catch fetch next from test1 into @tablename end close test1 deallocate test1 go