-
Notifications
You must be signed in to change notification settings - Fork 0
/
3_ddl_scripts.sql
125 lines (106 loc) · 2.87 KB
/
3_ddl_scripts.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
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
create table STUDENT
(
student_id serial
constraint STUDENT_pk
primary key,
student_nm varchar(255) not null,
student_id_card_no int,
student_group_no varchar(10),
student_tel bigint check(student_tel between 79000000000 and 79999999999)
);
create table ROOM
(
room_num varchar(4) primary key,
table_cnt smallint not null check(table_cnt >= 0),
chair_cnt smallint not null check(chair_cnt >= 0),
bookshelf_cnt smallint not null check(bookshelf_cnt >= 0),
wardrobe_cnt smallint not null check(wardrobe_cnt >= 0)
);
create table ACTIVIST
(
student_id int
constraint ACTIVIST_pk
primary key
constraint ACTIVIST_STUDENT_student_id_fk
references STUDENT (student_id),
hours_of_work_amt decimal not null check(hours_of_work_amt >= 0),
rating_cnt smallint not null check(rating_cnt >= 0)
);
create table MANAGER
(
occupation_nm varchar(255)
constraint MANAGER_pk
primary key,
student_id int
constraint MANAGER_STUDENT_student_id_fk
references STUDENT (student_id),
salary_amt decimal check(salary_amt >= 0)
);
create table RESPONSIBLE_ZONE
(
zone_nm varchar(255)
constraint RESPONSIBLE_ZONE_pk
primary key,
responsible_student_id int
constraint RESPONSIBLE_ZONE_STUDENT_student_id_fk
references STUDENT (student_id),
room_num varchar(4),
hours_per_month_salary_amt decimal check(hours_per_month_salary_amt >= 0)
);
create table ROOM_OF_STUDENT_COUNCIL
(
room_id varchar(20)
constraint ROOM_OF_STUDENT_COUNCIL_pk
primary key,
zone_nm varchar(255)
constraint ROOM_OF_STUDENT_COUNCIL_RESPONSIBLE_ZONE_zone_nm_fk
references RESPONSIBLE_ZONE (zone_nm),
rules_txt varchar
);
create table LOCK_LOG
(
enter_dttm timestamp
constraint LOCK_LOG_pk
primary key,
room_id varchar(20)
constraint LOCK_LOG_ROOM_OF_STUDENT_COUNCIL_room_id_fk
references ROOM_OF_STUDENT_COUNCIL (room_id),
id_card_no int not null,
access_granted_flag boolean not null
);
create table BAN_LIST
(
added_dttm timestamp
constraint BAN_LIST_pk
primary key,
room_id varchar(20)
constraint BAN_LIST_ROOM_OF_STUDENT_COUNCIL_room_id_fk
references ROOM_OF_STUDENT_COUNCIL (room_id),
student_id int
constraint BAN_LIST_STUDENT_student_id_fk
references STUDENT (student_id),
ends_dttm timestamp not null,
reason_txt varchar
);
create table STUDENT_X_ROOM
(
student_id int
constraint STUDENT_X_ROOM_pk
primary key
constraint STUDENT_X_ROOM_student_id_fk
references STUDENT (student_id),
room_num varchar(4)
constraint STUDENT_X_ROOM_room_num_fk
references ROOM (room_num)
);
create table ACCESS_MANAGER_X_ROOM_OF_SC
(
occupation_nm varchar(255)
constraint ACCESS_MANAGER_X_ROOM_OF_SC_occupation_nm_fk
references MANAGER (occupation_nm),
room_id varchar(30)
constraint ACCESS_MANAGER_X_ROOM_OF_SC_room_id_fk
references ROOM_OF_STUDENT_COUNCIL (room_id),
constraint ACCESS_MANAGER_X_ROOM_OF_SC_pk
primary key (occupation_nm, room_id)
);