0

I've got the following situation:

One table containing multiple foreign keys pointing to multiple tables, but only one foreign key to one table. If one record of the primary key is deleted I want to delete the record inside my foreign key table.

Foreign-Key-Table (FK-Column --> FK-Table):

fk_main --> pk_main_table

fk_column1 --> pk_table1

fk_column2 --> pk_table2

fk_column3 --> pk_table3

fk_column4 --> pk_table4

Only one of the fk_columns (fk_columnX) and the fk_main column containing information . The rest is NULL.

The problem is, that I can't create ON DELETE CASCACDE because of loops (but where are they?). Is there a way to get this working?

INFO: pk_table2 is child-member of pk_table1 and has a on delete cascade - but this shouldn't matter? Because if I delete the record in pk_table1 the records in pk_table2 are deleted too, so the cascade could also go to the foreign-key table?

I think I have to use Triggers regarding to this topic?: Foreign key constraint may cause cycles or multiple cascade paths?

John
  • 121
  • 10
  • Hi, why you can't create "ON DELETE CASCADE" constraint? – Tomasz Mar 05 '19 at 08:28
  • It says that the cascades create loops – John Mar 05 '19 at 08:30
  • Could you add simple schema with tables, constraints and options (on delete cascade, set null)? – Tomasz Mar 05 '19 at 08:49
  • Simply use ON DELETE CASCADE. Don't worry about loops. – jarlh Mar 05 '19 at 08:51
  • @jarlh I think he's saying he tried with `CASCADE` but got the error about loops (hence the linked post with the error). OP please add full create scripts for your tables. But if you cannot change any of the existing design you are probably limited to triggers as noted in your linked post. – Jacob H Mar 05 '19 at 17:57

0 Answers0