--声明必要变量
DECLARE @tablename NVARCHAR(80),@columnname NVARCHAR(20),@sql NVARCHAR(2000),@sql2 NVARCHAR(2000),@sql3 NVARCHAR(2000),@CName NVARCHAR(20)
SET @CName='RegionCode'
--游标
DECLARE cur CURSOR FOR
--1、查找包含某列的table
SELECT '['+TABLE_SCHEMA+'].['+TABLE_NAME+']' AS TableName,'['+COLUMN_NAME+']'
FROM [INFORMATION_SCHEMA].[COLUMNS]
WHERE [COLUMN_NAME] LIKE '%'+@CName+'%'
OPEN cur
FETCH NEXT FROM cur INTO @tablename,@columnname
while (@@fetch_status=0)
BEGIN
PRINT @tablename
--EXECUTE (@sql)
FETCH NEXT FROM cur INTO @tablename,@columnname
END
close cur
deallocate cur
GO