MySQL foreign key constraints, cascade delete
Posted
by Cudos
on Stack Overflow
See other posts from Stack Overflow
or by Cudos
Published on 2010-05-26T16:32:59Z
Indexed on
2010/05/26
20:51 UTC
Read the original article
Hit count: 224
Hello.
I want to use foreign keys to keep the integrity and avoid orphans (I already use innoDB).
How do I make a SQL statment that DELETE ON CASCADE?
Secondly, that using DELETE ON CASCADE. E.g. if I delete a category then it would delete products related to that category even though there are other categories related to those products.
The pivot table "categories_products" creates a many-to-many relationship between the two other tables.
categories
- id (INT)
- name (VARCHAR 255)
products
- id
- name
- price
categories_products
- categories_id
- products_id
© Stack Overflow or respective owner