-
Notifications
You must be signed in to change notification settings - Fork 0
/
Academy.sql
1091 lines (822 loc) · 17.7 KB
/
Academy.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
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--Cannot drop database because it is currently in use
USE [master]
ALTER DATABASE Academy SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
DROP database Academy;
-- Delete table with auto increment id
Truncate table Academy.dbo.Departments;
DROP table Academy.dbo.Departments;
-- Cannot truncate table because it is being referenced by a FOREIGN KEY constraint.
delete from Academy.dbo.Groups;
DBCC CHECKIDENT ('Academy.dbo.Departments', RESEED, 0);
create database Academy
use Academy
-- Teachers
create table Teachers
(
Id int primary key IDENTITY (1,1) NOT NULL,
[Teachers's name] nvarchar(max) NOT NULL,
[Teachers's surname] nvarchar(max) NOT NULL,
Constraint CK_TeacherName Check([Teachers's name] <>' '),
Constraint CK__TeacherSurname Check([Teachers's surname] <>' '),
)
Insert into Academy.dbo.Teachers(Academy.dbo.Teachers.[Teachers's name], Academy.dbo.Teachers.[Teachers's surname])
values
(N'Alex', N'Carmack'),
(N'Edward', N'Hopper'),
(N'Cavid',N'Oğuzlu'),
(N'Qıbçaq',N'Türksoy'),
(N'Orxan',N'Qüdrətli'),
(N'Bağır',N'Bağırzadə'),
(N'Səbinə',N'Fikrətli'),
(N'Zərifə',N'Osmanlı'),
(N'Samantha',N'Adams'),
(N'Kate',N'Brown'),
(N'Head 1 Teacher''s name', N'Head 1 Teacher''s surname'),
(N'Head 2 Teacher''s name', N'Head 2 Teacher''s surname'),
(N'Head 3 Teacher''s name', N'Head 3 Teacher''s surname'),
(N'Head 4 Teacher''s name', N'Head 4 Teacher''s surname'),
(N'Head 5 Teacher''s name', N'Head 5 Teacher''s surname'),
(N'Dean 1 Teacher''s name', N'Dean 1 Teacher''s surname'),
(N'Dean 2 Teacher''s name', N'Dean 2 Teacher''s surname'),
(N'Dean 3 Teacher''s name', N'Dean 3 Teacher''s surname'),
(N'Dean 4 Teacher''s name', N'Dean 4 Teacher''s surname'),
(N'Dean 5 Teacher''s name', N'Dean 5 Teacher''s surname'),
(N'Curator 1 Teacher''s name', N'Curator 1 Teacher''s surname'),
(N'Curator 2 Teacher''s name', N'Curator 2 Teacher''s surname'),
(N'Curator 3 Teacher''s name', N'Curator 3 Teacher''s surname'),
(N'Curator 4 Teacher''s name', N'Curator 4 Teacher''s surname'),
(N'Curator 5 Teacher''s name', N'Curator 5 Teacher''s surname'),
(N'Curator 6 Teacher''s name', N'Curator 6 Teacher''s surname'),
(N'Curator 7 Teacher''s name', N'Curator 7 Teacher''s surname'),
(N'Curator 8 Teacher''s name', N'Curator 8 Teacher''s surname'),
(N'Curator 9 Teacher''s name', N'Curator 9 Teacher''s surname'),
(N'Curator 10 Teacher''s name', N'Curator 10 Teacher''s surname')
select *from Academy.dbo.Teachers
-- Subjects
create table Subjects
(
Id int primary key IDENTITY (1,1) NOT NULL,
[Name of Subject] nvarchar(100) NOT NULL,
Constraint CK_Name_of_Subject Check([Name of Subject] <>' '),
Constraint UQ_Name_of_Subject Unique([Name of Subject])
)
Insert into Academy.dbo.Subjects(Academy.dbo.Subjects.[Name of Subject])
values
(N'Basics of Programming'),
(N'Algorithm'),
(N'Higher mathematics'),
(N'Basics of cybernetics'),
(N'Basics of physics'),
(N'Higher physics'),
(N'Basics of chemistry'),
(N'Higher chemistry'),
(N'Basics of statistics'),
(N'Database Theory'),
(N'Basics of econometrica'),
(N'Basics of economics'),
(N'Basics of sociology'),
(N'Religions and myths'),
(N'Basics of phiolosophy'),
(N'Metaphysics'),
(N'Basics of psychology'),
(N'Basics of anthropology')
select *from Academy.dbo.Subjects
-- Assistants
create table Assistants
(
Id int primary key IDENTITY (1,1) NOT NULL,
[TeacherId for Assistants] int NOT NULL,
Constraint FK_TeacherId_forAssistants Foreign key ([TeacherId for Assistants]) References Teachers(Id) On Delete CASCADE On Update CASCADE
)
Insert into Academy.dbo.Assistants(Academy.dbo.Assistants.[TeacherId for Assistants])
values
(2),
(4),
(6),
(8),
(10)
select *from Academy.dbo.Assistants
-- Lectures
create table Lectures
(
Id int primary key IDENTITY (1,1) NOT NULL,
[TeacherId for Lectures] int NOT NULL,
[SubjectId for Lectures] int NOT NULL,
Constraint FK_TeacherId_forLectures Foreign key ([TeacherId for Lectures]) References Teachers(Id) On Delete CASCADE On Update CASCADE,
Constraint FK_SubjectId_forLectures Foreign key ([SubjectId for Lectures]) References Subjects(Id) On Delete CASCADE On Update CASCADE
)
Insert into Academy.dbo.Lectures(Academy.dbo.Lectures.[TeacherId for Lectures], Academy.dbo.Lectures.[SubjectId for Lectures])
values
(1,1),
(1,2),
(2,1),
(2,2),
--
(1,3),
(1,4),
(2,4),
(2,3),
--
(3,5),
(4,6),
(3,6),
(4,5),
--
(3,7),
(4,7),
(4,8),
(3,8),
--
(5,9),
(6,9),
(5,10),
(6,10),
--
(5,11),
(6,12),
(5,12),
(6,11),
--
(7,13),
(8,13),
(7,14),
(8,14),
--
(7,15),
(8,16),
(7,16),
(8,15),
--
(9,17),
(10,18),
(9,18),
(10,17)
select *from Academy.dbo.Lectures
select
*from
Academy.dbo.Teachers as T,
Academy.dbo.Subjects as S,
Academy.dbo.Lectures as L
where
T.Id=L.[TeacherId for Lectures]
AND
S.Id= L.[SubjectId for Lectures]
Order by T.Id
-- Deans
create table Deans
(
Id int primary key IDENTITY (1,1) NOT NULL,
[TeacherId for Deans] int NOT NULL,
Constraint FK_TeacherId_forDeans Foreign key ([TeacherId for Deans]) References Teachers(Id) On Delete CASCADE On Update CASCADE
)
Insert into Academy.dbo.Deans(Academy.dbo.Deans.[TeacherId for Deans])
values
(11),
(12),
(13),
(14),
(15)
select *from Academy.dbo.Deans
-- Curators
create table Curators
(
Id int primary key IDENTITY (1,1) NOT NULL,
[TeacherId for Curators] int NOT NULL,
Constraint FK_TeacherId_forCurators Foreign key ([TeacherId for Curators]) References Teachers(Id) On Delete CASCADE On Update CASCADE
)
Insert into Academy.dbo.Curators(Academy.dbo.Curators.[TeacherId for Curators])
values
(21),
(22),
(23),
(24),
(25),
(26),
(27),
(28),
(29),
(30)
select *from Academy.dbo.Curators
select
*from
Academy.dbo.Teachers as T,
Academy.dbo.Curators as C
where
T.Id= C.[TeacherId for Curators]
-- Faculties
create table Faculties
(
Id int primary key IDENTITY (1,1) NOT NULL,
[Name of Faculty] nvarchar(100) NOT NULL,
Building int NOT NULL,
[DeanId for Faculties] int NOT NULL,
Constraint CK_Name_of_Faculty Check([Name of Faculty] <>' '),
Constraint UQ_Name_of_Faculty Unique([Name of Faculty]),
Constraint CK_Building Check(Building >=1 AND Building <=5),
Constraint FK_DeanId_forFaculties Foreign key ([DeanId for Faculties]) References Deans(Id) On Delete No Action On Update No Action
)
Insert into Academy.dbo.Faculties(Academy.dbo.Faculties.[Name of Faculty], Academy.dbo.Faculties.Building, Academy.dbo.Faculties.[DeanId for Faculties])
values
(N'Computer Science', 1, 1),
(N'Electronics', 1, 1),
(N'Physics', 2, 2),
(N'Chemistry', 2, 2),
(N'Statistics', 3, 3),
(N'Econometrica', 3, 3),
(N'Sociology', 4, 4),
(N'Philosophy', 4, 4),
(N'Psychology', 5, 5),
(N'Civil Engineering', 5, 5)
select *from Academy.dbo.Faculties
select
*from
Academy.dbo.Deans as D,
Academy.dbo.Faculties as F
where
F.[DeanId for Faculties] = D.Id
-- Heads
create table Heads
(
Id int primary key IDENTITY (1,1) NOT NULL,
[TeacherId for Heads] int NOT NULL,
Constraint FK_TeacherId_forHeads Foreign key ([TeacherId for Heads]) References Teachers(Id) On Delete CASCADE On Update CASCADE
)
Insert into Academy.dbo.Heads(Academy.dbo.Heads.[TeacherId for Heads])
values
(16),
(17),
(18),
(19),
(20)
select *from Academy.dbo.Heads
-- Departments
create table Departments
(
Id int primary key IDENTITY (1,1) NOT NULL,
[Name of Departments] nvarchar(100) NOT NULL,
Building int NOT NULL,
[FacultyId for Departments] int NOT NULL,
[HeadId for Departments] int NOT NULL,
Constraint CK_Name_of_Departments Check([Name of Departments] <>' '),
Constraint UQ_Name_of_Departments Unique([Name of Departments]),
Constraint CK_BuildingDepartments Check(Building >=1 AND Building <=5),
Constraint FK_FacultyId_forDepartments Foreign key ([FacultyId for Departments]) References Faculties(Id) On Delete NO ACTION On Update NO ACTION,
Constraint FK_HeadId_forDepartments Foreign key ([HeadId for Departments]) References Heads(Id) On Delete NO ACTION On Update NO ACTION
)
Insert into Academy.dbo.Departments(Academy.dbo.Departments.[Name of Departments], Academy.dbo.Departments.Building, Academy.dbo.Departments.[FacultyId for Departments], Academy.dbo.Departments.[HeadId for Departments])
values
(N'Software Development', 1, 1, 1),
(N'Software Development_2', 1, 2, 1),
(N'Software Development_3', 1, 1, 2),
(N'Physics and Chemistry', 2, 3, 2),
(N'Physics and Chemistry_2', 2, 4, 3),
(N'Statistics and Econometrica', 3, 5, 3),
(N'Statistics and Econometrica_2', 3, 6, 4),
(N'Sociology and Philosophy', 4, 7, 4),
(N'Sociology and Philosophy_2', 4, 8, 5),
(N'Psychology', 5, 9, 5),
(N'Civil Engineering', 5, 10, 1)
select *from Academy.dbo.Departments
select
*from
Academy.dbo.Faculties as F,
Academy.dbo.Heads as H,
Academy.dbo.Departments as D,
Academy.dbo.Teachers as T
where
F.Id=D.[FacultyId for Departments]
AND
H.Id=D.[HeadId for Departments]
AND
H.[TeacherId for Heads] = T.Id
-- Groups
create table Groups
(
Id int primary key IDENTITY (1,1) NOT NULL,
[Name of Group] nvarchar(10) NOT NULL,
[Year of Group] int NOT NULL,
[DepartmentId for Groups] int NOT NULL,
Constraint FK_DepartmentId_forGroups Foreign key ([DepartmentId for Groups]) References Departments(Id) On Delete No Action On Update No Action,
Constraint CK_Name_of_Group Check([Name of Group] <>' '),
Constraint UQ_Name_of_Group Unique([Name of Group]),
Constraint CK_Year_of_Group Check([Year of Group] >=1 AND [Year of Group]<=5)
)
Insert into Academy.dbo.Groups([Name of Group], [Year of Group], [DepartmentId for Groups])
values
(N'F505', 5, 1),
(N'B103', 5, 1),
(N'C226', 4, 2),
(N'D221', 4, 2),
(N'A213', 3, 3),
(N'Q289', 3, 3),
(N'V214', 2, 4),
(N'J283', 2, 4),
(N'F205', 1, 5),
(N'B203', 1, 5),
(N'C326', 5, 1),
(N'D421', 5, 1),
(N'A613', 4, 2),
(N'Q589', 4, 2),
(N'V714', 3, 3),
(N'J973', 3, 3),
(N'A870', 2, 4),
(N'Q849', 2, 4),
(N'V584', 1, 5),
(N'J974', 1, 5)
select *from Academy.dbo.Groups
-- Groups and Lectures
create table [Groups and Lectures]
(
Id int primary key IDENTITY (1,1) NOT NULL,
[GroupId for Groups and Lectures] int NOT NULL,
[LectureId for Groups and Lectures] int NOT NULL,
Constraint FK_GroupId_forGroupsandLectures Foreign key ([GroupId for Groups and Lectures]) References Groups(Id) On Delete CASCADE On Update CASCADE,
Constraint FK_LectureId_forGroupsandLectures Foreign key ([LectureId for Groups and Lectures]) References Lectures(Id) On Delete CASCADE On Update CASCADE
)
Insert into Academy.dbo.[Groups and Lectures]([GroupId for Groups and Lectures], [LectureId for Groups and Lectures])
values
(1,1),
(1,2),
(1,3),
(1,4),
(1,5),
(1,6),
(1,7),
(1,8),
(1,9),
(1,10),
(2, 1),
(2, 2),
(2, 3),
(2, 4),
(2, 5),
(2, 6),
(2, 7),
(2, 8),
(2, 9),
(2, 10),
(2, 13),
(2, 14),
(2, 15),
(2, 16),
(2, 21),
(2, 22),
(2, 23),
(2, 24),
(2, 25),
(2, 26),
(2, 27),
(2, 28),
(2, 29),
(2, 30),
(2, 31),
(2, 32),
(2, 33),
(2, 34),
(2, 35),
(2, 36),
(3, 1),
(3, 2),
(3, 3),
(3, 4),
(3, 5),
(3, 6),
(3, 7),
(3, 8),
(3, 9),
(3, 10),
(3, 11),
(3, 12),
(3, 13),
(3, 14),
(3, 15),
(3, 16),
(3, 17),
(3, 18),
(3, 19),
(3, 20),
(4, 1),
(4, 2),
(4, 3),
(4, 4),
(4, 5),
(4, 6),
(4, 7),
(4, 8),
(4, 9),
(4, 10),
(4, 11),
(4, 12),
(4, 13),
(4, 14),
(4, 15),
(4, 16),
(4, 17),
(4, 18),
(4, 19),
(4, 20),
(4, 21),
(4, 22),
(4, 23),
(4, 24),
(4, 25),
(4, 26),
(4, 27),
(5, 1),
(5, 2),
(5, 3),
(5, 4),
(5, 5),
(5, 6),
(5, 7),
(5, 8),
(5, 9),
(5, 10),
(5, 11),
(5, 12),
(5, 13),
(5, 14),
(5, 15),
(5, 16),
(5, 17),
(5, 18),
(5, 19),
(5, 20),
(6, 1),
(6, 2),
(6, 3),
(6, 4),
(6, 5),
(6, 6),
(6, 7),
(6, 8),
(6, 9),
(6, 10),
(6, 11),
(6, 12),
(6, 13),
(6, 14),
(6, 15),
(6, 16),
(6, 17),
(7, 1),
(7, 2),
(7, 3),
(7, 4),
(7, 5),
(7, 6),
(7, 7),
(7, 8),
(7, 9),
(7, 10),
(8, 1),
(8, 2),
(8, 3),
(8, 4),
(8, 5),
(8, 6),
(8, 7),
(8, 8),
(8, 9),
(8, 10),
(9, 1),
(9, 2),
(9, 3),
(9, 4),
(9, 5),
(9, 6),
(9, 7),
(9, 8),
(9, 9),
(9, 10),
(10, 1),
(10, 2),
(10, 3),
(10, 4),
(10, 5),
(10, 6),
(10, 7),
(10, 8),
(10, 9),
(10, 10),
(11, 1),
(11, 2),
(11, 3),
(11, 4),
(11, 5),
(11, 6),
(11, 7),
(11, 8),
(11, 9),
(11, 10),
(11, 21),
(11, 22),
(11, 23),
(11, 24),
(11, 25),
(11, 26),
(11, 27),
(11, 28),
(11, 29),
(11, 30),
(12, 1),
(12, 2),
(12, 3),
(12, 4),
(12, 5),
(12, 6),
(12, 7),
(12, 8),
(12, 9),
(12, 10),
(13, 1),
(13, 2),
(13, 3),
(13, 4),
(13, 5),
(13, 6),
(13, 7),
(13, 8),
(13, 9),
(13, 10),
(14, 1),
(14, 2),
(14, 3),
(14, 4),
(14, 5),
(14, 6),
(14, 7),
(14, 8),
(14, 9),
(14, 10),
(14, 11),
(14, 12),
(14, 13),
(14, 14),
(14, 15),
(14, 16),
(14, 17),
(14, 18),
(14, 19),
(14, 20),
(15, 1),
(15, 2),
(15, 3),
(15, 4),
(15, 5),
(15, 6),
(15, 7),
(15, 8),
(15, 9),
(15, 10),
(16, 1),
(16, 2),
(16, 3),
(16, 4),
(16, 5),
(16, 6),
(16, 7),
(16, 8),
(16, 9),
(16, 10),
(16, 11),
(16, 12),
(16, 13),
(16, 14),
(16, 15),
(16, 16),
(16, 17),
(16, 18),
(16, 19),
(16, 20),
(17, 11),
(17, 12),
(17, 13),
(17, 14),
(17, 15),
(17, 16),
(17, 17),
(17, 18),
(17, 19),
(17, 20),
(18, 1),
(18, 2),
(18, 3),
(18, 4),
(18, 5),
(18, 6),
(18, 7),
(18, 8),
(18, 9),
(18, 10),
(19, 1),
(19, 2),
(19, 3),
(19, 4),
(19, 5),
(19, 6),
(19, 7),
(19, 8),
(19, 9),
(19, 10),
(20, 1),
(20, 2),
(20, 3),
(20, 4),
(20, 5),
(20, 6),
(20, 7),
(20, 8),
(20, 9),
(20, 10)
select *from Academy.dbo.Lectures
select *from Academy.dbo.Groups
select *from Academy.dbo.[Groups and Lectures]
select
*from
Academy.dbo.Groups as G,
Academy.dbo.Lectures as L,
Academy.dbo.[Groups and Lectures] as GL
where
G.Id =GL.[GroupId for Groups and Lectures]
AND
L.Id=GL.[LectureId for Groups and Lectures]
-- Groups and Curators
create table [Groups and Curators]
(
Id int primary key IDENTITY (1,1) NOT NULL,
[CuratorId for Groups and Curators] int NOT NULL,
[GroupId for Groups and Curators] int NOT NULL,
Constraint FK_CuratorId_forGroupsandCurators Foreign key ([CuratorId for Groups and Curators]) References Curators(Id) On Delete CASCADE On Update CASCADE,
Constraint FK_GroupId_forGroupsandCurators Foreign key ([GroupId for Groups and Curators]) References Groups(Id) On Delete CASCADE On Update CASCADE
)
Insert into Academy.dbo.[Groups and Curators](Academy.dbo.[Groups and Curators].[CuratorId for Groups and Curators], Academy.dbo.[Groups and Curators].[GroupId for Groups and Curators])
values
(1,1),
(1,9),
(2,2),
(2,10),
(3,3),
(3,11),
(4,4),
(4,12),
(5,5),
(5,13),
(6,6),
(6,14),
(7,7),
(7,15),
(8,8),
(8,16),
(9,17),
(9,18),
(10,19),
(10,20)
select *from Academy.dbo.Curators
select *from Academy.dbo.Groups
select *from Academy.dbo.[Groups and Curators]
select
*from
Academy.dbo.Curators as C,
Academy.dbo.Groups as G,
Academy.dbo.[Groups and Curators] as GC,
Academy.dbo.Teachers as T
where
GC.[CuratorId for Groups and Curators]= C.Id
AND
GC.[GroupId for Groups and Curators]= G.Id
AND
T.Id = C.[TeacherId for Curators]
-- LectureRooms
create table LectureRooms
(
Id int primary key IDENTITY (1,1) NOT NULL,
[Name of Classroom] nvarchar(10) NOT NULL,
Building int NOT NULL,
Constraint CK_Name_of_Classroom Check([Name of Classroom] <>' '),
Constraint UQ_Name_of_Classroom Unique([Name of Classroom]),
Constraint CK_BuildingClassroom Check(Building >=1 AND Building <=5)
)
Insert Into Academy.dbo.LectureRooms (Academy.dbo.LectureRooms.[Name of Classroom], Academy.dbo.LectureRooms.Building)
values
(N'A311',5),
(N'A104',5),
(N'A211',5),
(N'A404',5),
(N'B311',4),
(N'B104',4),
(N'B211',4),
(N'B404',4),
(N'C311',3),
(N'C104',3),
(N'C211',3),
(N'C404',3),
(N'D311',2),
(N'D104',2),
(N'D211',2),
(N'D404',2),
(N'E311',1),
(N'E104',1),
(N'E211',1),
(N'E404',1)
select *from Academy.dbo.LectureRooms
-- Schedules
create table Schedules
(
Id int primary key IDENTITY (1,1) NOT NULL,
[Double period] int NOT NULL,
[Day of week] int NOT NULL,
[Week number of lecture] int NOT NULL,
[LectureId for Schedules] int NOT NULL,
[LectureRoomsId for Schedules] int NOT NULL,
Constraint CK_DoublePeriod Check([Double period] >=1 AND [Double period] <=8),
Constraint CK_DayofWeek Check([Day of week] >=1 AND [Day of week] <=7),
Constraint CK_WeeknumberofLecture Check([Week number of lecture] >=1 AND [Week number of lecture] <=52),
Constraint FK_LectureId_forSchedules Foreign key ([LectureId for Schedules]) References Lectures(Id) On Delete NO ACTION On Update NO ACTION,
Constraint FK_LectureRoomsId_forSchedules Foreign key ([LectureRoomsId for Schedules]) References LectureRooms(Id) On Delete NO ACTION On Update NO ACTION
)