-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.sql
More file actions
202 lines (161 loc) · 6.86 KB
/
Copy pathcreate.sql
File metadata and controls
202 lines (161 loc) · 6.86 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*==============================================================*/
/* DBMS name: PostgreSQL 9.x */
/* Created on: 25.10.2019 18:01:24 */
/*==============================================================*/
drop index Groups_PK;
drop table Groups;
drop index Groups_Posts2_FK;
drop index Groups_Posts_FK;
drop index Groups_Posts_PK;
drop table Groups_Posts;
drop index Posts_Notification_FK;
drop index Notificstion_PK;
drop table Notificstion;
drop index Posts_PK;
drop table Posts;
drop index User_PK;
drop table "User";
drop index User_Groups2_FK;
drop index User_Groups_FK;
drop index User_Groups_PK;
drop table User_Groups;
/*==============================================================*/
/* Table: Groups */
/*==============================================================*/
create table Groups (
group_id NUMERIC(10) not null,
group_name VARCHAR(20) null,
group_topic VARCHAR(20) null,
constraint PK_GROUPS primary key (group_id)
);
/*==============================================================*/
/* Index: Groups_PK */
/*==============================================================*/
create unique index Groups_PK on Groups (
group_id
);
/*==============================================================*/
/* Table: Groups_Posts */
/*==============================================================*/
create table Groups_Posts (
group_id NUMERIC(10) not null,
post_id NUMERIC(10) not null,
constraint PK_GROUPS_POSTS primary key (group_id, post_id)
);
/*==============================================================*/
/* Index: Groups_Posts_PK */
/*==============================================================*/
create unique index Groups_Posts_PK on Groups_Posts (
group_id,
post_id
);
/*==============================================================*/
/* Index: Groups_Posts_FK */
/*==============================================================*/
create index Groups_Posts_FK on Groups_Posts (
group_id
);
/*==============================================================*/
/* Index: Groups_Posts2_FK */
/*==============================================================*/
create index Groups_Posts2_FK on Groups_Posts (
post_id
);
/*==============================================================*/
/* Table: Notificstion */
/*==============================================================*/
create table Notificstion (
notification_id NUMERIC(10) not null,
post_id NUMERIC(10) null,
notification_time VARCHAR(5) null,
notification_text VARCHAR(100) null,
constraint PK_NOTIFICSTION primary key (notification_id)
);
/*==============================================================*/
/* Index: Notificstion_PK */
/*==============================================================*/
create unique index Notificstion_PK on Notificstion (
notification_id
);
/*==============================================================*/
/* Index: Posts_Notification_FK */
/*==============================================================*/
create index Posts_Notification_FK on Notificstion (
post_id
);
/*==============================================================*/
/* Table: Posts */
/*==============================================================*/
create table Posts (
post_id NUMERIC(10) not null,
post_content VARCHAR(10000) null,
post_hashtag VARCHAR(20) null,
constraint PK_POSTS primary key (post_id)
);
/*==============================================================*/
/* Index: Posts_PK */
/*==============================================================*/
create unique index Posts_PK on Posts (
post_id
);
/*==============================================================*/
/* Table: "User" */
/*==============================================================*/
create table "User" (
id_user NUMERIC(10) not null,
name_user VARCHAR(20) null,
constraint PK_USER primary key (id_user)
);
/*==============================================================*/
/* Index: User_PK */
/*==============================================================*/
create unique index User_PK on "User" (
id_user
);
/*==============================================================*/
/* Table: User_Groups */
/*==============================================================*/
create table User_Groups (
id_user NUMERIC(10) not null,
group_id NUMERIC(10) not null,
constraint PK_USER_GROUPS primary key (id_user, group_id)
);
/*==============================================================*/
/* Index: User_Groups_PK */
/*==============================================================*/
create unique index User_Groups_PK on User_Groups (
id_user,
group_id
);
/*==============================================================*/
/* Index: User_Groups_FK */
/*==============================================================*/
create index User_Groups_FK on User_Groups (
id_user
);
/*==============================================================*/
/* Index: User_Groups2_FK */
/*==============================================================*/
create index User_Groups2_FK on User_Groups (
group_id
);
alter table Groups_Posts
add constraint FK_GROUPS_P_GROUPS_PO_GROUPS foreign key (group_id)
references Groups (group_id)
on delete restrict on update restrict;
alter table Groups_Posts
add constraint FK_GROUPS_P_GROUPS_PO_POSTS foreign key (post_id)
references Posts (post_id)
on delete restrict on update restrict;
alter table Notificstion
add constraint FK_NOTIFICS_POSTS_NOT_POSTS foreign key (post_id)
references Posts (post_id)
on delete restrict on update restrict;
alter table User_Groups
add constraint FK_USER_GRO_USER_GROU_USER foreign key (id_user)
references "User" (id_user)
on delete restrict on update restrict;
alter table User_Groups
add constraint FK_USER_GRO_USER_GROU_GROUPS foreign key (group_id)
references Groups (group_id)
on delete restrict on update restrict;