This repository has been archived by the owner on Mar 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tables.sql
executable file
·76 lines (59 loc) · 2.4 KB
/
tables.sql
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
Create Database Meawer;
use Meawer;
Create table Kittens (
id_kitten int not null auto_increment,
username varchar(50) not null,
email varchar(50) not null,
password varchar(50) not null,
name varchar(50) not null,
surname varchar(50) not null,
register_date datetime not null default current_timestamp,
born_date datetime not null,
image varchar(50),
background_image varchar(50),
Primary Key (id_kitten)
);
Create table Meaws (
id_meaw int not null auto_increment,
id_kitten int not null,
image varchar(50),
publish_date datetime not null default current_timestamp,
content varchar(280) not null default '',
Primary Key (id_meaw)
);
Create table Re_Meaws (
id_meaw int not null auto_increment,
id_kitten int not null,
re_meaw_date datetime not null default current_timestamp,
Primary Key (id_meaw, id_kitten),
Unique (id_meaw, id_kitten)
);
Create table Comments (
id_comment int not null auto_increment,
id_meaw int not null,
id_kitten int not null,
coment_date datetime not null default current_timestamp,
content varchar(280) not null default '',
Primary Key (id_comment)
);
Create table Purrs_x_Meaw (
id_kitten int not null,
id_meaw int not null,
Primary Key (id_kitten, id_meaw),
Unique (id_kitten, id_meaw)
);
Create table Purrs_x_Comment (
id_kitten int not null,
id_comment int not null,
Primary Key (id_kitten, id_comment),
Unique (id_kitten, id_comment)
);
Alter table Meaws add Constraint FK_Meaws_Kitten Foreign Key (id_kitten) references Kittens(id_kitten);
Alter table Re_Meaws add Constraint FK_ReMeaws_Kitten Foreign Key (id_kitten) references Kittens(id_kitten);
Alter table Re_Meaws add Constraint FK_ReMeaws_Meaw Foreign Key (id_meaw) references Meaws(id_meaw);
Alter table Comments add Constraint FK_Comments_Meaw Foreign Key (id_meaw) references Meaws(id_meaw);
Alter table Comments add Constraint FK_Comments_Kitten Foreign Key (id_kitten) references Kittens(id_kitten);
Alter table Purrs_x_Meaw add Constraint FK_PurrsMeaw_Kitten Foreign Key (id_kitten) references Kittens(id_kitten);
Alter table Purrs_x_Meaw add Constraint FK_PurrsMeaw_Meaw Foreign Key (id_meaw) references Meaws(id_meaw);
Alter table Purrs_x_Comment add Constraint FK_PurrsComment_Kitten Foreign Key (id_kitten) references Kittens(id_kitten);
Alter table Purrs_x_Comment add Constraint FK_PurrsComment_Comment Foreign Key (id_comment) references Comments(id_comment);