日期:2014-05-18 浏览次数:20394 次
DECLARE @WHAT VARCHAR(800) SET @WHAT='178' --要搜索的字符串 DECLARE @SQL VARCHAR(8000) DECLARE TABLECURSOR CURSOR LOCAL FOR SELECT SQL='IF EXISTS ( SELECT 1 FROM ['+ S.NAME + '].['+O.NAME+'] WHERE ['+C.NAME+'] LIKE ''%'+@WHAT+'%'' ) PRINT ''所在的表及字段:['+O.NAME+'].['+C.NAME+']''' FROM SYSCOLUMNS C JOIN SYS.OBJECTS O ON C.ID=O.OBJECT_ID JOIN SYS.SCHEMAS S ON O.SCHEMA_ID = S.SCHEMA_ID WHERE S.NAME != 'SYS' -- 175=CHAR 56=INT 可以查 SELECT * FROM SYS.TYPES AND O.XTYPE='U' AND C.STATUS>=0 AND C.XUSERTYPE IN (175, 239, 231, 167 ) /*把这个WHERE改下*/ OPEN TABLECURSOR FETCH NEXT FROM TABLECURSOR INTO @SQL WHILE @@FETCH_STATUS=0 BEGIN EXEC( @SQL ) FETCH NEXT FROM TABLECURSOR INTO @SQL END CLOSE TABLECURSOR