Not sure why no one suggested but I use sp_fkeys
to query foreign keys for a given table:
(不知道为什么没有人建议,但是我使用sp_fkeys
查询给定表的外键:)
EXEC sp_fkeys 'TableName'
You can also specify the schema:
(您还可以指定架构:)
EXEC sp_fkeys @pktable_name = 'TableName', @pktable_owner = 'dbo'
Without specifying the schema, the docs state the following:
(在未指定架构的情况下, 文档指出以下内容:)
If pktable_owner is not specified, the default table visibility rules of the underlying DBMS apply.
(如果未指定pktable_owner,则适用基础DBMS的默认表可见性规则。)
In SQL Server, if the current user owns a table with the specified name, that table's columns are returned.
(在SQL Server中,如果当前用户拥有具有指定名称的表,则返回该表的列。)
If pktable_owner is not specified and the current user does not own a table with the specified pktable_name, the procedure looks for a table with the specified pktable_name owned by the database owner. (如果未指定pktable_owner并且当前用户不拥有具有指定pktable_name的表,则该过程将查找数据库所有者拥有的具有指定pktable_name的表。)
If one exists, that table's columns are returned. (如果存在,则返回该表的列。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…