简体   繁体   English

查询以查找所有FK约束及其删除规则(SQL Server)

[英]Query to find all FK constraints and their delete rules (SQL Server)

In SQL Server 2005, can I issue an SQL query to list all FK constraints on tables within the DB, and show the delete rule? 在SQL Server 2005中,我可以发出SQL查询来列出数据库中表的所有FK约束,并显示删除规则吗? (ie nothing, cascade, set null, or set default) (即没有,级联,设置为null或设置默认值)

The output I'm looking for is something akin to: 我正在寻找的输出类似于:

FK_NAME                  ON_DELETE
==================================
FK_LINEITEM_STATEMENT    CASCADE
FK_ACCOUNTREP_CLIENT     NOTHING

You can try this: 你可以试试这个:

SELECT name, delete_referential_action_desc
FROM sys.foreign_keys

这里游戏的后期不多,但你也可以试试这个:

select * from INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS

You can use also expression in the WHERE block: 您还可以在WHERE块中使用表达式:

objectproperty(object_id('FK_your_constraint_name'), 'CnstIsDeleteCascade')

or 要么

objectproperty(your_constraint_object_id, 'CnstIsDeleteCascade')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM