2017-07-13 64 views
0

SQL Server 2016中是否有任何方法或工具根据名称在整个数据库中查找列?如何在SQL Server数据库中查找特定列?

例子:找到ProductNumber,它显示你所有的表(S)有它

+2

'选择* information_schema.columns在列名=“ProductNumber'' –

回答

1

您可以查询数据库的information_schema.columns表,持有数据库中定义的所有列的架构结构。

使用此查询:

select * from information_schema.columns where column_name = 'ProductNumber' 

结果会给你的列:该数据库列

TABLE_NAMETABLE_CATALOGDATA_TYPE和更多的属性。

1

您可以使用查询,如下:

select * 
from information_schema.columns 
where column_name = 'ProductNumber' 
1

有几个选项供您选择:

SELECT * 
FROM information_schema.columns 
WHERE column_name = 'YourColumnName'; 

-- OR 

SELECT col.name, tab.name 
FROM sys.columns col 
INNER JOIN sys.tables tab 
    ON tab.object_id = col.object_id 
WHERE col.name = 'YourColumnName'; 
1

如果你需要按名称查找数据库对象(如表,列,触发器) - 看看所谓SQL Search免费红门工具这样做 - 它会搜索你的整个数据库中的任何类型的字符串。

enter image description here

enter image description here

这是一个伟大的必须具备的任何DBA或数据库开发人员工具 - 为什么我已经提到它的绝对免费用于任何用途的?

0
SELECT 
so.name "table name", 
sc.name "column name" 
FROM sysobjects so 
INNER JOIN syscolumns sc 
ON so.id = sc.id 
WHERE --so.type='U' 

--and

sc.name like '%ProductN%' 
order by so.name asc 
相关问题