When using “on delete cascade” in mySQL,
- use INNODB;
- index foreign key field.
Example:
create table user ( user_id bigint(20) unsigned not null auto_increment primary key) ENGINE=INNODB;
create table foto (
foto_id bigint(20) unsigned not null auto_increment primary key,
user_id bigint(20) unsigned not null,
index (user_id),
foreign key (user_id) references user (user_id) on delete cascade on update no action
) ENGINE=INNODB;
A. Yudha said
thanks
index on foreign is must ?
harish said
ya its true,its executed