-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtables.sql
More file actions
77 lines (63 loc) · 2.31 KB
/
tables.sql
File metadata and controls
77 lines (63 loc) · 2.31 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
use blog_site;
-- *****************************************************************************************
-- user table
create table user (
user_id int primary key auto_increment,
phone_no varchar(15),
srn varchar(20),
name varchar(100),
password varchar(100),
email varchar(100)
);
-- *****************************************************************************************
-- post table
create table post (
post_id int primary key auto_increment,
title varchar(255),
content text,
user_id int,
post_date datetime,
no_of_likes int default 0,
post_time datetime,
foreign key (user_id) references user(user_id) on delete cascade
);
-- *****************************************************************************************
-- comment table
create table comment (
comment_id int primary key auto_increment,
comment_content text,
user_id int,
post_id int,
comment_time datetime,
foreign key (user_id) references user(user_id) on delete cascade,
foreign key (post_id) references post(post_id) on delete cascade
);
-- *****************************************************************************************
-- category table
create table category (
category_id int primary key auto_increment,
category_name varchar(100) unique
);
-- this table only stores the categories and their ids
-- *****************************************************************************************
-- post_category junction table
create table post_category (
post_id int,
category_id int,
primary key (post_id, category_id),
foreign key (post_id) references post(post_id) on delete cascade,
foreign key (category_id) references category(category_id) on delete cascade
);
-- this table is meant to associate the posts in the database with categories based on category id
-- *****************************************************************************************
-- post_likes table
create table post_likes (
post_id int,
user_id int,
time_of_like datetime,
primary key (post_id, user_id),
foreign key (post_id) references post(post_id) on delete cascade,
foreign key (user_id) references user(user_id) on delete cascade
);
-- *****************************************************************************************
show tables;