SQL Server 按名称搜索列 [英] SQL Server search for a column by name

查看:29
本文介绍了SQL Server 按名称搜索列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一些侦察工作,不得不在几百个 SQL Server 数据库表中查找列.

I'm doing some recon work and having to dig through a few hundred SQL Server database tables to find columns.

有没有一种方法可以轻松搜索数据库中的列并只返回该列所属的表名?

Is there a way to easily search for columns in the database and return just the table name that the column belongs to?

我找到了 this,但这也返回了包含该列名的存储过程...

I found this, but that also returns Stored procedures with that column name in it...

推荐答案

SELECT OBJECT_NAME(object_id) FROM sys.columns WHERE name = 'foo'

虽然这包括视图,但可以进一步过滤.不过可能有用.

This includes views though but can be further filtered . It may be useful though.

更一般的...

SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'foo'

sys.columns

这篇关于SQL Server 按名称搜索列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆