'cascade on delete' in mysql

what mean cascade on delete ??

this means if parent record deleted, the child records referencing parent pk also deleted

create table tb_parent (
 id int not null,
fd varchar(100) not null,
primary key (id)

create table tb_child(
id int not null,
pid int default null,
fd varchar(100) default null,
primary key (id),
key ix_parentid(pid),
constraint child_ibfk_1 foreign key (pid) references tb_parent (id) on delete cascade

insert into tb_parent values (1, 'parent-1'), (2, 'parent-2');

insert into tb_child values(100, 1, 'childe-100');


Popular posts from this blog

codefights smooth sailing ( CommonCharacterCount)

How to remove 8443 port in URL in tomcat