I'm deleting a row in a table that is on one site of a many-to-many relationship. I would also like to delete any related rows on the other side of that relationship.
For example, let's say I have the following tables and I want to delete a row from Cars
. I would also want to delete any related rows from Drivers
and, of course, any rows no longer needed in CarDrivers
.
Table Cars:
CarID int
CarName nvarchar(100)
Table Drivers:
DriverID int
DriverName nvarchar(100)
Table CarDrivers:
CarID int
Driver int
I know how to join the tables above in a SELECT
query. But I don't see how to delete data across the relationship.
Note: Both sides of the relationship implement cascading deletes. So, for example, deleting a row from Cars
will delete any related rows in CarDrivers
. But obviously that doesn't propagate to the Drivers
table.