How can I list all foreign keys referencing a given table in SQL Server?

Posted BI Information

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了How can I list all foreign keys referencing a given table in SQL Server?相关的知识,希望对你有一定的参考价值。

1. EXEC sp_fkeys ‘TableName‘

2. SELECT obj.name AS FK_NAME,
sch.name AS [schema_name],
tab1.name AS [table],
col1.name AS [column],
tab2.name AS [referenced_table],
col2.name AS [referenced_column]
FROM sys.foreign_key_columns fkc
INNER JOIN sys.objects obj
ON obj.object_id = fkc.constraint_object_id
INNER JOIN sys.tables tab1
ON tab1.object_id = fkc.parent_object_id
INNER JOIN sys.schemas sch
ON tab1.schema_id = sch.schema_id
INNER JOIN sys.columns col1
ON col1.column_id = parent_column_id AND col1.object_id = tab1.object_id
INNER JOIN sys.tables tab2
ON tab2.object_id = fkc.referenced_object_id
INNER JOIN sys.columns col2
ON col2.column_id = referenced_column_id AND col2.object_id = tab2.object_id



















以上是关于How can I list all foreign keys referencing a given table in SQL Server?的主要内容,如果未能解决你的问题,请参考以下文章

sql 一种表值函数,可将XML转换为表。感谢http://stackoverflow.com/questions/2266132/how-can-i-get-a-list-of-element

sh 列出Git远程分支(来自http://stackoverflow.com/questions/3471827/how-do-i-list-all-remote-branches-in-git-1

009:How can I test if an array contains a certain value?

How do I add elements to a Scala List?

How can I add files to a Jar file?

How to solve Nissan Consult 3 plus can't see no vehicle in list