2

我正在使用 SQL Server 2012,想知道是否有办法在给定数据库中查找包含特定列的所有表?

4

2 回答 2

3
select
    quotename(S.name) + '.' + quotename(T.name) as [Table]
from sys.columns C
    join sys.tables T on T.object_id = C.object_id
    join sys.schemas S on S.schema_id = T.schema_id
where C.name = 'ColumnName'
order by 1
于 2013-08-08T19:27:38.007 回答
2

I think the easiest way is to use the INFORMATION_SCHEMA.COLUMNS table:

select c.SCHEMA_NAME, c.TABLE_NAME
from INFORMATION_SCHEMA.COLUMNS c
where c.COLUMN_NAME = @YOURCOLUMNNAME;
于 2013-08-08T20:34:56.490 回答