Skip to content

Instantly share code, notes, and snippets.

@jaredbeck
Created Apr 13, 2017
Embed
What would you like to do?
drop table if exists d;
drop table if exists c;
drop table if exists b;
drop table if exists a;
create table a (
id int not null auto_increment,
primary key (id)
);
create table b (
id int not null auto_increment,
a_id int not null,
primary key (id),
foreign key (a_id) references a (id) on delete cascade
);
create table c (
id int not null auto_increment,
a_id int not null,
primary key (id),
foreign key (a_id) references a (id) on delete cascade
);
create table d (
id int not null auto_increment,
b_id int not null,
c_id int not null,
primary key (id),
foreign key (b_id) references b (id) on delete cascade,
foreign key (c_id) references c (id) on delete restrict
);
insert into a (id) values (1);
insert into b (id, a_id) values (1, 1);
insert into c (id, a_id) values (1, 1);
insert into d (id, b_id, c_id) values (1, 1, 1);
delete from a;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment