Skip to content

Instantly share code, notes, and snippets.

@jaredbeck
Created April 13, 2017 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredbeck/4aad0749164337b2e67eb10e81fb5ee3 to your computer and use it in GitHub Desktop.
Save jaredbeck/4aad0749164337b2e67eb10e81fb5ee3 to your computer and use it in GitHub Desktop.
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