-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLCourseDatabaseMySQL.sql
More file actions
236 lines (207 loc) · 6.06 KB
/
SQLCourseDatabaseMySQL.sql
File metadata and controls
236 lines (207 loc) · 6.06 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
drop database if exists SQLCourseDatabase;
create database SQLCourseDatabase collate cp1251_general_ci;
use SQLCourseDatabase;
drop table if exists Teacher_Course_Faculty;
drop table if exists Students_marks;
drop table if exists Group_Student;
drop table if exists Groups;
drop table if exists Students;
drop table if exists Courses;
drop table if exists Teachers;
drop table if exists Faculties;
create table Faculties(
faculty_id int auto_increment primary key,
faculty_name nvarchar(255)
);
create table Courses(
course_id int auto_increment primary key,
course_name nvarchar(255)
);
create table Teachers(
teacher_id int auto_increment primary key,
last_name nvarchar(255) not null,
first_name nvarchar(255) not null,
birthday datetime,
curator_id int,
constraint fk_teachers_teachers
foreign key (curator_id)
references Teachers(teacher_id)
);
create table Students(
student_id int auto_increment primary key,
student_number nvarchar(128) not null,
last_name nvarchar(255) not null,
first_name nvarchar(255) not null,
sex bit not null,
birthday datetime
);
create table Groups(
group_id int auto_increment primary key,
group_number nvarchar(24),
faculty_id int not null,
constraint fk_groups_faculties
foreign key (faculty_id)
references Faculties(faculty_id)
);
create table Group_Student(
group_student_id int auto_increment primary key,
group_id int not null,
student_id int not null,
is_head bit not null,
constraint fk_groups_students_groups
foreign key (group_id)
references Groups(group_id),
constraint fk_groups_students_students
foreign key (student_id)
references Students(student_id)
);
create table Teacher_Course_Faculty(
teacher_course_faculty_id int auto_increment primary key,
teacher_id int not null,
course_id int not null,
faculty_id int not null,
duration decimal(8,2),
constraint fk_teacher_course_faculty_teachers
foreign key (teacher_id)
references Teachers(teacher_id),
constraint fk_teacher_course_faculty_course
foreign key (course_id)
references Courses(course_id),
constraint fk_teacher_course_faculty_faculties
foreign key (faculty_id)
references Faculties(faculty_id)
);
create table Students_marks(
student_mark_id int auto_increment primary key,
student_id int not null,
course_id int not null,
mark int,
constraint fk_students_marks_students
foreign key (student_id)
references Students(student_id),
constraint fk_students_marks_courses
foreign key (course_id)
references Courses(course_id)
);
insert into Faculties
(faculty_name)
values
('Математико-механический'),
('Физический'),
('Экономический');
insert into Courses
(course_name)
values
('Алгебра'),
('Геометрия'),
('Высшая математика'),
('Оптика'),
('История'),
('Теория вероятностей'),
('Экономическая теория');
insert into Teachers
(last_name, first_name, birthday, curator_id)
values
('Петров', 'Иван', '19640413', null),
('Никитин', 'Сергей', '19610623', null),
('Иванов', 'Олег', '19451001', null),
('Носов', 'Максим', '19721225', 2),
('Алексеев', 'Алексей', '19690312', null),
('Данилов', 'Александр', '19790422', 1),
('Сидоров', 'Денис', '19750502', 1),
('Лаптев', 'Андрей', '19710719', null),
('Стеклов', 'Никита', '19500820', 2),
('Оленев', 'Игорь', '19401025', 3);
insert into Students
(student_number, last_name, first_name, sex, birthday)
values
('12', 'Таранов', 'Максим', 1, '19891212'),
('23', 'Жуков', 'Андрей', 1, '19891023'),
('45', 'Шарапова', 'Анна', 0, '19860107'),
('67', 'Власова', 'Светлана', 0, '19860308'),
('89', 'Алиев', 'Искандер', 1, '19860427'),
('234', 'Кузнецов', 'Павел', 1, '19850502'),
('567', 'Кузнецова', 'Алла', 0, '19850507'),
('28', 'Миронов', 'Андрей', 1, '19850528'),
('13', 'Голубева', 'Полина', 0, '19850507'),
('93', 'Орлов', 'Андрей', 1, '19850917'),
('123', 'Толстой', 'Стас', 1, '19890606'),
('654', 'Иванов', 'Сергей', 1, '19851207'),
('987', 'Сидорова', 'Анастасия', 0, '19841124');
insert into Groups
(group_number, faculty_id)
values
('13', 1),
('14', 1),
('13', 2),
('13', 3),
('15', 2);
insert into Group_Student
(group_id, student_id, is_head)
values
(1, 1, 1),
(1, 2, 0),
(1, 3, 0),
(2, 4, 1),
(2, 5, 0),
(2, 6, 0),
(2, 7, 0),
(3, 8, 1),
(3, 9, 0),
(4, 10, 1),
(4, 11, 0),
(4, 12, 0),
(5, 13, 1);
insert into Students_marks
(student_id, course_id, mark)
values
(1, 1, 5),
(1, 2, 4),
(1, 3, 4),
(1, 4, 3),
(1, 7, 5),
(2, 1, 4),
(2, 3, 5),
(2, 6, 3),
(2, 7, 5),
(3, 2, 4),
(3, 3, 4),
(3, 5, 3),
(3, 6, 4),
(4, 1, 5),
(4, 6, 4),
(5, 7, 5),
(5, 4, 4),
(6, 2, 3),
(6, 3, 5),
(6, 7, 4),
(7, 3, 4),
(7, 7, 5),
(7, 4, 4),
(8, 1, 3),
(8, 2, 5),
(8, 7, 4),
(8, 3, 5),
(9, 2, 4),
(10, 1, 4),
(10, 2, 3),
(10, 3, 4),
(10, 6, 3),
(12, 3, 4);
insert into Teacher_Course_Faculty
(teacher_id, course_id, faculty_id, duration)
values
(1, 1, 1, 80),
(1, 2, 1, 56),
(1, 3, 2, 90),
(2, 6, 1, 40),
(3, 4, 2, 32),
(4, 7, 3, 202),
(5, 3, 1, 86),
(5, 3, 3, 62),
(7, 4, 2, 34),
(7, 6, 2, 24),
(8, 2, 3, 26),
(9, 1, 1, 88),
(9, 3, 3, 74),
(9, 6, 3, 62);