user2135970
user2135970

Reputation: 815

Programatically Identify All Foreign Keys that Cascade

I need to use SQL to identify all foreign keys that have a cascading delete. Can someone tell me where I can find out whether a foreign key is cascading?

Thanks!

Upvotes: 1

Views: 48

Answers (2)

Bozman
Bozman

Reputation: 477

you can look in informatation_schema

select * from INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
where DELETE_RULE = 'CASCADE' OR UPDATE_RULE = 'CASCADE'

Upvotes: 1

Aaron Bertrand
Aaron Bertrand

Reputation: 280272

SELECT * FROM sys.foreign_keys 
  WHERE delete_referential_action > 0
     OR update_referential_action > 0;

Upvotes: 3

Related Questions