declare @key varchar(30)
set @key = '广州' --替换为要查找的字符串DECLARE @tabName VARCHAR(40),@colName VARCHAR(40)DECLARE @sql VARCHAR(2000)declare @tsql varchar(8000)DECLARE tabCursor CURSOR FORSELECT name from ccfs3.dbo.sysobjects WHERE xtype = 'u' AND name <> 'dtproperties'OPEN tabCursorFETCH NEXT from tabCursor INTO @tabNameWHILE @@fetch_status = 0BEGINset @tsql = ''DECLARE colCursor CURSOR FOR Select Name from SysColumns Where id=Object_Id(@tabName) --and xtype=167OPEN colCursorFETCH NEXT from colCursor INTO @colNameWHILE @@fetch_status = 0BEGINSET @sql = 'if(exists(select * from ' + @tabName + ' where 'SET @sql = @sql + @colName + ' like ''%' + @key + '%'')) begin select * from 'set @sql = @sql + @tabName + ' where ' + @colName + ' like ''%' + @key + '%'';select '''+ @tabName + ''' as TableName end'set @tsql = @tsql + @sql + ';'print @tsqlFETCH NEXT from colCursor INTO @colNameENDexec(@tsql)CLOSE colCursorDEALLOCATE colCursorFETCH NEXT from tabCursor INTO @tabNameENDCLOSE tabCursorDEALLOCATE tabCursor