on delete cascade in mySQL

When using “on delete cascade” in mySQL,

  1. use INNODB;
  2. 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;

mySQL reference

2 Comments »

  1. A. Yudha said

    thanks
    index on foreign is must ?

  2. harish said

    ya its true,its executed

RSS feed for comments on this post · TrackBack URI

Leave a Comment