Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If There is a relation between two tables then how to delete a row from main table(related records also should be deleted from related table).How can we write sql query...?
Posted

You can use have a foreign key to the other table with the CASCADE option on.
See here[^] to read more about this.
 
Share this answer
 
Comments
[no name] 4-Aug-11 10:50am    
Exactly the same thing I said with the same link.
Abhinav S 4-Aug-11 13:04pm    
I suppose we both posted at the same time.
yarakiran 4-Aug-11 10:52am    
THANKS ITS WORKING
First of all if this is a requirement then you should have the the tables configure to support it, on delete cascade[^]

Otherwise

SQL
DELETE FROM child_table
WHERE parentID = @ID

DELETE FROM table
WHER id = @ID
 
Share this answer
 

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