Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL Server
Expertise: Beginner
Jul 16, 1999

Cascade Delete

Question:
What is the syntax for doing a cascade delete in SQL? For instance, I have a table with a parent record that has child records in other tables, filtering down many levels. How do I delete out of the parent table and all of the children tables in one command?

Answer:
Cascade deletes aren't delivered 'out of the box' like the other Declarative Referential Integrity actions.

In order to accomplish what you are after, you need to do your own child record deletes by starting at the bottom and working your way 'up' (back to the parent record contributing the foreign key in the child table). Once you delete the child records, you will be able to delete the parents.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date