查询以获取具有特定列名称的所有表名称

时间:2017-06-11 14:02:39

标签: sql sql-server sql-server-2008

如何在SQL Server 2008中获取所有具有名为CreatedBy的列的表。

2 个答案:

答案 0 :(得分:0)

在Sql Server中,您可以通过查看sys.columns

来获取此信息
  use DB_MAST_AERRE
  select 
         OBJECT_SCHEMA_NAME(object_id) AS SchemaName,
         object_name(object_id) AS TableName
         from 
            sys.columns
            where name = 'CreatedBy'

答案 1 :(得分:0)

use [AdventureWorks2014]
go

declare @columnname varchar(50)
set @columnname='CreatedBy'

select a.name as columnname ,b.name as tablename
from sys.columns a
inner join sys.tables b
on a.object_id=b.object_id
where a.name like '%'+@columnname+'%'