Skip to content

Instantly share code, notes, and snippets.

@artemrogov
Created August 20, 2018 20:42
Show Gist options
  • Save artemrogov/93d53ca631c3fb629a8bff5570f38fdd to your computer and use it in GitHub Desktop.
Save artemrogov/93d53ca631c3fb629a8bff5570f38fdd to your computer and use it in GitHub Desktop.
create simple database for joins
create table customers
(
id int auto_increment,
user_name varchar(255) null,
constraint customers_id_uindex
unique (id)
);
alter table customers
add primary key (id);
create table orders
(
id int auto_increment
primary key,
user_id int null,
total int null,
constraint user_id
foreign key (user_id) references customers (id)
on update cascade
on delete cascade
);
create table stores
(
id int auto_increment
primary key,
name varchar(255) null
);
create table products
(
id int auto_increment
primary key,
name varchar(255) not null,
store_id int null,
constraint store_id
foreign key (store_id) references stores (id)
on update cascade
on delete cascade
);
create table orders_details
(
id int auto_increment
primary key,
store_id int null,
product_id int null,
qt int null,
total double null,
order_id int null,
constraint order_id
foreign key (order_id) references orders (id)
on update cascade
on delete cascade,
constraint product_id_fk
foreign key (product_id) references products (id),
constraint store_id_fk
foreign key (store_id) references stores (id)
on update cascade
on delete cascade
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment