Try this:
DELETE t1,t2,t3 FROM table1 as t1
JOIN table2 as t2 ON t2.ID = t1.ID
JOIN table3 as t3 ON t3.ID = t1.ID
Your
eventID
in all table will make it work.
For
deleting records from multiple tables:
You could define
Foreign Key constraints
(
which you have defined as EventID) for the other tables that reference the master table's ID with
ON DELETE CASCADE.
This would cause the related rows in those tables to be deleted. This is the least programming model, is part of the
SQL
standard, etc. Just be sure that you think through the issues with
always deleting the referencing rows.
Refer for more details:
http://msdn.microsoft.com/en-us/library/ms174979.aspx[
^]
You could create a
delete trigger
on the table where you delete the master row for the
ID that would then contain code to delete related rows
from other tables.
You still have to write the code for this one, but it hides inside the
trigger
and is used by any deletes from the table as long as the
trigger
is not disabled.
Refer for more details:
http://msdn.microsoft.com/en-us/library/ms189799.aspx[
^]