Click here to Skip to main content
15,886,791 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey guys,

I'm kinda stuck now so I might ask as well, I already created a 2 tables with 2 columns in a relationship. How can I use cascade delete to automatically delete the foreign key rows when the primary key row got deleted?

I dont get how the code block for this thing works, all the example I saw have the table and column creation mixed with the code block and other codes that makes it hard for me to understand.
Posted

1 solution

This may not be what you are looking for, but personally I never use cascading deletes.

If I do find the need to delete the primary key table to a foreign key constraint, I first just delete all the rows with that foreign key

i.e.

delete from customersales where customerId = 23
delete from customer where customerid = 23


that way I am in control, and I needn't worry about someone accidentally deleting a whole bunch of records they didn't mean to!
 
Share this answer
 
Comments
KatsuneShinsengumi 18-Mar-14 13:12pm    
Thanks for the info, I just want my related tables to become efficient in terms of handling rows. I'll use that approach as a backup.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900