我正在使用SQL Server 2012,并想知道是否有办法找到包含某个列的给定数据库中的所有表?
答案 0 :(得分:2)
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
答案 1 :(得分:1)
我认为最简单的方法是使用INFORMATION_SCHEMA.COLUMNS
表:
select c.SCHEMA_NAME, c.TABLE_NAME
from INFORMATION_SCHEMA.COLUMNS c
where c.COLUMN_NAME = @YOURCOLUMNNAME;