· 8 years ago · Apr 16, 2018, 02:26 PM
1drop database if exists loja_online;
2create database loja_online;
3use loja_online;
4
5drop table if exists clothing;
6drop table if exists clothing_picture;
7drop table if exists clothing_type;
8drop table if exists clothing_details;
9drop table if exists color;
10drop table if exists cliente;
11drop table if exists packaging;
12
13create table clothing(
14 id int(4) primary key auto_increment,
15 id_type int(2) NOT NULL,
16 nome varchar(50) NOT NULL,
17 description varchar(500) NOT NULL,
18 id_color int (3) NOT NULL,
19 id_picture int(5),
20 price decimal(4,2) NOT NULL,
21 FOREIGN KEY (id_type) REFERENCES clothing_type(id),
22 FOREIGN KEY (id_picture) REFERENCES clothing_picture(id),
23 FOREIGN KEY (id_color) REFERENCES clothing_color(id)
24);
25
26create table clothing_picture(
27 id int(5) primary key auto_increment,
28 id_clothing int(4) NOT NULL,
29 path varchar(200) NOT NULL,
30 FOREIGN KEY (id_clothing) REFERENCES clothing(id)
31);
32
33create table clothing_type(
34 id int(2) primary key auto_increment,
35 id_clothing int(4) NOT NULL,
36 tipo varchar(30) NOT NULL,
37 FOREIGN KEY (id_clothing) REFERENCES clothing(id)
38);
39
40create table clothing_details(
41 id int (5) primary key auto_increment,
42 id_clothing int(4) NOT NULL,
43 id_size int(2) NOT NULL,
44 units int(4),
45 FOREIGN KEY (id_clothing) REFERENCES clothing(id),
46 FOREIGN KEY (id_size) REFERENCES clothing_size(id)
47);
48
49create table clothing_color(
50 id int (3) primary key auto_increment,
51 color varchar(20) NOT NULL,
52 image varchar(200) NOT NULL
53);
54
55create table clothing_size(
56 id int (2) primary key auto_increment,
57 size varchar(5) NOT NULL
58);