MySQL - Verknüpfte Daten löschen wenn Tupel gelöscht wird?

1 Antwort

Vom Fragesteller als hilfreich ausgezeichnet

Du musst beim Fremdschlüssel einfach das löschverhalten (ON_DELETE) auf cascade stellen.

https://dev.mysql.com/doc/refman/8.0/en/create-table-foreign-keys.html

When an UPDATE or DELETE operation affects a key value in the parent table that has matching rows in the child table, the result depends on the referential action specified by ON UPDATE and ON DELETE subclauses of the FOREIGN KEY clause. Referential actions include:
CASCADE: Delete or update the row from the parent table and automatically delete or update the matching rows in the child table. Both ON DELETE CASCADE and ON UPDATE CASCADE are supported. Between two tables, do not define several ON UPDATE CASCADE clauses that act on the same column in the parent table or in the child table.
...
ColdertronHD 
Fragesteller
 10.12.2021, 02:32

Ahh super vielen Dank. Das ist genau das was ich gesucht habe. Das hat mir sehr weiter geholfen :D

0