Click here to Skip to main content
14,697,231 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am facing a problem where i have a table(table1) of primary key constraint and a second table(table2) having a foreign key constraint for table one of particular field .
If i delete a row in table1 i get a error where i need to delete in table2 as well .
Is there a way or a query where if i delete a row in table1 the following foreign key constraint in table2 should automatically get deleted .

thanks in advance
Vivek Krishnamurthy 7-Mar-12 12:48pm
You question is not clear, you mean to do cascaded delete from table 2 ?
mohanrajkiller 8-Mar-12 7:57am
i dont know the technical term i am not an expert in sql

1 solution

What you can do is to set the Delete Rule of your foreign key to Cascade. See here[^] for steps on how to do it. What basically happens when you set it that way is that, when a record in table1 gets deleted, the corresponding record(through foreign key) in table2 will be deleted as well.

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