-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.sql
194 lines (173 loc) · 6.87 KB
/
script.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
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
CREATE TABLE faculty(
faculty_code smallint NOT NULL PRIMARY KEY,
name character(20) NOT NULL,
abbreviation character(10)
);
CREATE TABLE course(
course_code smallint NOT NULL PRIMARY KEY,
name character(20) NOT NULL,
faculty_code smallint NOT NULL,
FOREIGN KEY(faculty_code) REFERENCES faculty(faculty_code) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE groups(
group_number character(20) NOT NULL PRIMARY KEY,
name character(20) NOT NULL,
course_code smallint NOT NULL,
FOREIGN KEY(course_code) REFERENCES course(course_code) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE order_type(
order_type_id smallint NOT NULL PRIMARY KEY,
name character(20) NOT NULL
);
CREATE TABLE orders(
order_number smallint NOT NULL PRIMARY KEY,
order_points character(50) NOT NULL,
order_type_id smallint NOT NULL,
FOREIGN KEY(order_type_id) REFERENCES order_type(order_type_id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE student(
student_id smallint NOT NULL PRIMARY KEY,
full_name character(50) NOT NULL,
date_of_birth character(50) NOT NULL,
phone_number character(20),
address character(20),
group_number character(10) NOT NULL,
order_number smallint NOT NULL,
FOREIGN KEY(group_number) REFERENCES groups(group_number) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(order_number) REFERENCES orders(order_number) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE enrollee(
enrollee_id smallint NOT NULL PRIMARY KEY,
full_name character(50) NOT NULL,
date_of_birth date NOT NULL,
phone_number character(20) ,
address character(50),
exam_scores smallint NOT NULL,
course_code smallint NOT NULL,
CHECK( (exam_scores >= 0) AND (exam_scores <= 100) ),
FOREIGN KEY(course_code) REFERENCES course(course_code) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE student_move(
student_move_id smallint NOT NULL PRIMARY KEY,
student_id smallint NOT NULL,
order_number smallint NOT NULL,
FOREIGN KEY(student_id) REFERENCES student(student_id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(order_number) REFERENCES orders(order_number) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE department(
department_code smallint NOT NULL PRIMARY KEY,
name character(20) NOT NULL,
abbreviation character(10),
faculty_code smallint NOT NULL,
FOREIGN KEY(faculty_code) REFERENCES faculty(faculty_code) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE discipline(
discipline_code smallint NOT NULL PRIMARY KEY,
name smallint NOT NULL,
department_code smallint NOT NULL,
FOREIGN KEY(department_code) REFERENCES department(department_code) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE curriculum_discipline(
cur_discipline_id smallint NOT NULL PRIMARY KEY,
discipline_code smallint NOT NULL,
course_number smallint NOT NULL,
semester smallint NOT NULL,
lesson_type character(20) NOT NULL,
CHECK( (course_number >= 1) AND (course_number <= 4) ),
CHECK( (semester >= 1) AND (semester <= 8) ),
FOREIGN KEY(discipline_code) REFERENCES discipline(discipline_code) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE grade(
grade_id smallint NOT NULL PRIMARY KEY,
student_id smallint NOT NULL,
grade smallint NOT NULL,
exam_date date,
cur_discipline_id smallint NOT NULL,
CHECK( (grade >= 2) AND (grade <= 5) ),
FOREIGN KEY(student_id) REFERENCES student(student_id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(cur_discipline_id) REFERENCES curriculum_discipline(cur_discipline_id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE scholarship_type(
scholar_type_id smallint NOT NULL PRIMARY KEY,
name character(20) NOT NULL,
payment_amount real NOT NULL,
CHECK( payment_amount > 0 )
);
CREATE TABLE scholarship(
scholar_id smallint NOT NULL PRIMARY KEY,
student_id smallint NOT NULL,
scholar_type_id smallint NOT NULL,
order_number smallint NOT NULL,
FOREIGN KEY(student_id) REFERENCES student(student_id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(scholar_type_id) REFERENCES scholarship_type(scholar_type_id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(order_number) REFERENCES orders(order_number) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE salary(
salary_id smallint NOT NULL PRIMARY KEY,
payment_amount real NOT NULL,
order_number smallint NOT NULL,
CHECK( payment_amount > 0 ),
FOREIGN KEY(order_number) REFERENCES orders(order_number) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE professor(
professor_id smallint NOT NULL PRIMARY KEY,
full_name character(50) NOT NULL,
phone_number character(20),
address character(50),
department_code smallint NOT NULL,
position character(20) NOT NULL,
degree character(20) NOT NULL,
salary_id smallint NOT NULL,
FOREIGN KEY(department_code) REFERENCES department(department_code) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(salary_id) REFERENCES salary(salary_id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE schedule(
schedule_id smallint NOT NULL PRIMARY KEY,
group_number character NOT NULL,
professor_id smallint NOT NULL,
cur_discipline_id smallint NOT NULL,
lesson_time time NOT NULL,
classroom character(20) NOT NULL,
FOREIGN KEY(group_number) REFERENCES groups(group_number) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(professor_id) REFERENCES professor(professor_id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(cur_discipline_id) REFERENCES curriculum_discipline(cur_discipline_id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE professor_move(
professor_move_id smallint NOT NULL PRIMARY KEY,
professor_id smallint NOT NULL,
order_number smallint NOT NULL,
FOREIGN KEY(professor_id) REFERENCES professor(professor_id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(order_number) REFERENCES orders(order_number) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE order_acception(
order_accept_id smallint NOT NULL PRIMARY KEY,
order_number smallint NOT NULL,
status character(20) NOT NULL,
acception_date date NOT NULL,
signed_by character(20),
FOREIGN KEY(order_number) REFERENCES orders(order_number) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE enrollee_document(
enrollee_doc_id smallint NOT NULL PRIMARY KEY,
enrollee_id smallint NOT NULL,
doc_type character(20) NOT NULL,
date_of_issue date,
place_of_issue character(50),
FOREIGN KEY(enrollee_id) REFERENCES enrollee(enrollee_id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE student_document(
student_doc_id smallint NOT NULL PRIMARY KEY,
student_id smallint NOT NULL,
doc_type character(20) NOT NULL,
date_of_issue date,
place_of_issue character(50),
FOREIGN KEY(student_id) REFERENCES student(student_id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE professor_document(
prof_doc_id smallint NOT NULL PRIMARY KEY,
professor_id smallint NOT NULL,
doc_type character(20) NOT NULL,
date_of_issue date,
place_of_issue character(50) ,
FOREIGN KEY(professor_id) REFERENCES professor(professor_id) ON DELETE CASCADE ON UPDATE CASCADE
);