Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql alter table relationship cascade

Tags:

mysql

I have this piece of code to alter a tables relationship but I want to add cascade update and delete operations do I need to add cascade update cascade delete to this code

ALTER TABLE product_images
ADD FOREIGNKEY (product_id) REFERENCES products(product_id)

this is a one to many relationship I hope my code is right for a start. I have a products table and a product_images table which has many images for each product

Updated

ALTER TABLE product_images
ADD FOREIGN KEY (product_id) REFERENCES products(product_id)
like image 619
ONYX Avatar asked Sep 03 '26 14:09

ONYX


1 Answers

Those referential actions need to be specified. RESTRICT is default.

like image 98
Kermit Avatar answered Sep 06 '26 22:09

Kermit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!