Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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? (ie nothing, cascade, set null, or set default)

The output I'm looking for is something akin to:

FK_NAME                  ON_DELETE
==================================
FK_LINEITEM_STATEMENT    CASCADE
FK_ACCOUNTREP_CLIENT     NOTHING
like image 914
Synesso Avatar asked Oct 06 '10 23:10

Synesso


2 Answers

You can try this:

SELECT name, delete_referential_action_desc
FROM sys.foreign_keys
like image 190
bobs Avatar answered Dec 18 '22 16:12

bobs


Little late to the game here, but you might also try this:

select * from INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
like image 29
Brian Avatar answered Dec 18 '22 16:12

Brian