How do I create a SQL DELETE statement to delete rows in a 3rd table?
You could try a subquery with an IN clause. Something like:
DELETE FROM OrderData WHERE OrderData.Order_ID IN(SELECT OrderInfo.Order_ID FROM OrderInfoJOIN CustData on OrderData.Order_ID = OrderInfo.Order_ID WHERE CustData.Bus_Name = 'Albertsons')
to test the query before deleting just do this: (will return all rows that would be deleted by the delete query)
SELECT * FROM OrderData WHERE OrderData.Order_ID IN(SELECT OrderInfo.Order_ID FROM OrderInfoJOIN CustData on OrderData.Order_ID = OrderInfo.Order_ID WHERE CustData.Bus_Name = 'Albertsons')
You can't.
SQLite (under v3.6.19) does not support foreign key constraints
, but you can use triggers
for exampleCheck this it will help you.
If you have v 3.6.19, it already support foreign constraints with ON UPDATE
or DELETE CASCADE
Read SQLite Foreign Key Support
EDIT:
OR like wrote @Paul Sasik