-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatements.sql
More file actions
139 lines (121 loc) · 3.33 KB
/
statements.sql
File metadata and controls
139 lines (121 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
create table test.blog
(
id int auto_increment
primary key,
title varchar(45) null,
content varchar(255) null
);
create table test.product
(
id bigint(100) auto_increment,
name varchar(100) not null,
description varchar(300) not null,
category varchar(20) not null,
withdrawn tinyint(1) not null,
tag_id bigint null,
constraint id
unique (id),
constraint name
unique (name)
);
alter table test.product
add primary key (id);
create table test.shop
(
id bigint(100) auto_increment,
name varchar(100) not null,
address varchar(100) not null,
lng double not null,
lat double not null,
withdrawn tinyint(1) not null,
brand varchar(100) null,
constraint address
unique (address),
constraint id
unique (id),
constraint name
unique (name)
);
alter table test.shop
add primary key (id);
create table test.tag
(
id bigint(100) auto_increment
primary key,
value varchar(45) not null
);
create table test.product_tag
(
product_id bigint(100) not null,
tag_id bigint(100) not null,
primary key (product_id, tag_id),
constraint p_id
foreign key (product_id) references product (id)
on update cascade on delete cascade,
constraint t_id
foreign key (tag_id) references tag (id)
on update cascade on delete cascade
);
create index p_id_idx
on test.product_tag (product_id);
create index t_id_idx
on test.product_tag (tag_id);
create table test.shop_tag
(
shop_id bigint(100) not null,
tag_id bigint(100) not null,
primary key (shop_id, tag_id),
constraint s_id
foreign key (shop_id) references shop (id)
on update cascade on delete cascade,
constraint tt_id
foreign key (tag_id) references tag (id)
on update cascade on delete cascade
);
create index s_id_idx
on test.shop_tag (shop_id);
create index tt_id_idx
on test.shop_tag (tag_id);
create table test.volunteer
(
id bigint(100) auto_increment,
username varchar(20) not null,
firstname varchar(20) not null,
lastname varchar(20) not null,
phone varchar(10) not null,
email varchar(45) not null,
dateofbirth date not null,
dateofreg datetime not null,
constraint email
unique (email),
constraint id_UNIQUE
unique (id),
constraint username
unique (username)
);
alter table test.volunteer
add primary key (id);
create table test.price
(
product_id bigint(100) not null,
shop_id bigint(100) not null,
volunteer_id bigint(100) not null,
value double not null,
timestamp datetime not null,
primary key (product_id, shop_id, volunteer_id, timestamp),
constraint pp_id
foreign key (product_id) references product (id)
on update cascade on delete cascade,
constraint ss_id
foreign key (shop_id) references shop (id)
on update cascade on delete cascade,
constraint vv_id
foreign key (volunteer_id) references volunteer (id)
on update cascade on delete cascade
);
create index shop_id_idx
on test.price (shop_id);
create index timestamp_idx
on test.price (timestamp);
create index volunteer_id_idx
on test.price (volunteer_id);