Is cascading deletion enabled?

Is there a way to check if a table is included in Cascade Delete? I am looking at script tables (from SQL Server) and I do not see any signs of Cascade Delete.

+4
source share
3 answers

For foreign key relationships, use sys.foreign_keys .

Column - delete_referential_action will help you find out if there is a deletion in the cascade.

http://technet.microsoft.com/en-us/library/ms189807.aspx

Below is a certificate of similar work:

 sys.default_constraints for default constraints on columns sys.check_constraints for check constraints on columns sys.key_constraints for key constraints (eg primary keys) sys.foreign_keys for foreign key relations 

Source: SQL Server 2008- Get Table Constraints

+4
source

You can use INFORMATION_SCHEMA for a standard approach like

 select * from INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS where DELETE_RULE ='CASCADE' 
+8
source

I found how to do this:

I wrote FK to the table in a new query window:

 ALTER TABLE [dbo].[myTable] WITH CHECK ADD CONSTRAINT [FK_myTable_myTableHeaders] FOREIGN KEY([ID]) REFERENCES [dbo].[myTableHeaders] ([_ID]) ON DELETE CASCADE GO 

How I was able to confirm this.

0
source

Source: https://habr.com/ru/post/1485056/


All Articles