Find Column dependency(查找列依赖)
问题描述
如何查找依赖于表格特定列的对象.
How to find objects which depend on particular column of table.
例如:
表:SomeTable
Table: SomeTable
列:col1 PK,col2,col3
Cols: col1 pk, col2, col3
我想找到所有依赖 col1 (Pk) 的对象
I want to find all the objects which are dependent on col1 (Pk)
推荐答案
试试这个查询,它会给你一些我认为你正在寻找的结果.
要进行过滤,请在 c1.name 或 c2.name 列中搜索值.
要查找对某个列的所有引用,请使用 c2.name 作为列名,并使用 OBJECT_NAME(k.referenced_object_id) 作为包含 c2 列的表:)
Try this query, it will get you some results that i think you are looking for.
To filter, search for the value in the c1.name or c2.name column.
To look for all the references to a certain column, use the c2.name for the column name and the OBJECT_NAME(k.referenced_object_id) as the table which holds the c2 column :)
祝你好运!
select OBJECT_NAME(k.parent_object_id) as parentTable
, c1.name as parentColumn
, OBJECT_NAME(k.referenced_object_id) as referencedTable
, c2.name as referencedColumn
from sys.foreign_keys k
inner join sys.foreign_key_columns f
on f.parent_object_id = k.parent_object_id
and f.constraint_object_id = k.object_id
inner join sys.columns c1
on c1.column_id = f.parent_column_id
and c1.object_id = k.parent_object_id
inner join sys.columns c2
on c2.column_id = f.referenced_column_id
and c2.object_id = k.referenced_object_id
where c2.name = 'Column'
and OBJECT_NAME(k.referenced_object_id) = 'Table'
这篇关于查找列依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:查找列依赖


基础教程推荐
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 带更新的 sqlite CTE 2022-01-01