--声明必要变量 DECLARE @tablename NVARCHAR(80),@columnname NVARCHAR(20),@sql NVARCHAR(2000),@sql2 NVARCHAR(2000),@sql3 NVARCHAR(2000),@CName NVARCHAR(20) SET @CName='AccountId' --游标 DECLARE cur CURSOR FOR --1、查找包含某列的table SELECT '['+TABLE_SCHEMA+'].['+TABLE_NAME+']' AS TableName,'['+COLUMN_NAME+']' FROM [INFORMATION_SCHEMA].[COLUMNS] WHERE [COLUMN_NAME] = @CName --2、查找包含某关键字的table --SELECT TABLE_NAME,TABLE_TYPE --FROM [INFORMATION_SCHEMA].[TABLES] --WHERE TABLE_NAME LIKE'% %' OPEN cur FETCH NEXT FROM cur INTO @tablename,@columnname while (@@fetch_status=0) BEGIN SET @sql='select top 100 '''+@tablename+''' as TName,* from '+ @tablename +' where '+字段名=具体值 PRINT @sql --EXECUTE (@sql) FETCH NEXT FROM cur INTO @tablename,@columnname END close cur deallocate cur GO