Jump to content

2 tables: ON DELETE CASCADE


itazev

Recommended Posts

Hey everyone!

 

I have these 2 tables and I am trying to design it in a way that when a product is deleted from the catalog it also get its entry removed from the installation table.

 

The situation is: each installation has its own products list on it. but what if a product is no longer available? the installations having that product should remove it from the list.

 

Appreciate any help!

 

create table products
(
id int unsigned auto_increment not null primary key,
description varchar(64),
price float(5,2) unsigned
)type=InnoDB;

create table inst_products
(FOREIGN KEY (inst_id) references installation(inst_id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (descID) references products(id) ON DELETE NO ACTION,
inst_id int unsigned not null,
unints smallint unsigned, 
descID int unsigned not null
)type=InnoDB;

Link to comment
https://forums.phpfreaks.com/topic/51377-2-tables-on-delete-cascade/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.