sql - Delete relative row from three different tables in mySQL -


i have following tables.

corp_id (pk) | corp_name ---------------------------------------- 1                   | freshfruit  2                   | realsteel 3                   | firmwall  corp_id (fk)| empl_id (pk) | empl_name -------------------------------------------------------- 1                   | 1                   | andy 1                   | 2                   | maria 2                   | 3                   | john 2                   | 4                   | neil 3                   | 5                   | stephan 3                   | 6                   | darwing  empl_id (fk)| client_id (pk)| client_name --------------------------------------------------------------- 1                   | 1                    | moris 1                   | 2                    | bean 1                   | 3                    | bay 3                   | 4                    | phill 4                   | 5                    | hank 5                   | 6                    | suzy 

if delete row in table 1, how delete rows in table 2 related fk deleted row in table 1, , delete rows in table 3 related fk deleted rows in table 2? in advance.

drop exisitng foreign key constraints , add them again on delete cascade:

alter table table2 drop foreign key corp_id  alter table table2 add constraint fk_2 foreign key (corp_id) references table1 on delete cascade; 

make similar changes third table.


Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -