Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Cerca il nome di una colonna in tutti i database

Questo script cercherà la tua colonna in tutte le tabelle in tutti i database.

Create table #yourcolumndetails(DBaseName varchar(100), TableSchema varchar(50), TableName varchar(100),ColumnName varchar(100), DataType varchar(100), CharMaxLength varchar(100))

EXEC sp_MSForEachDB @command1='USE [?];
    INSERT INTO #yourcolumndetails SELECT
    Table_Catalog
    ,Table_Schema
    ,Table_Name
    ,Column_Name
    ,Data_Type
    ,Character_Maximum_Length
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE COLUMN_NAME like ''%yourcolumnname%'''

select * from #yourcolumndetails
Drop table #yourcolumndetails