Friday, April 01, 2005

Delete Child Table Rows Using Parent Table Rows (SQL)

I ran into this article when working on a deletion of child records using a parent record's fields for evaluation. Hopefully someone else will find this useful too.



You can find the article by Thom Pantazi here.



I did alter his code a bit as I was about to delete all rows from my child table instead of the ones that matched my criteria. Here is my final statements:




DELETE ChildTable

WHERE ParentId IN (SELECT ParentId FROM ParentTable WHERE Criteria = 1)



DELETE ParentId WHERE Criteria = 1

No comments: