-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProject3MainScript.sql
More file actions
2659 lines (2269 loc) · 92.3 KB
/
Project3MainScript.sql
File metadata and controls
2659 lines (2269 loc) · 92.3 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
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
--------------------------------------- CREATE THE DATABASE ------------------------------------------
-- Step 1 Instructions: run only lines 4 and 5 using the master databse
--USE master
CREATE DATABASE [ClassSchedule_9:15_Group1];
GO
--USE master
--DROP DATABASE [ClassSchedule_9:15_Group1]
--GO
--------------------------------------- CREATE SCHEMAS ------------------------------------------
-- Step 2 Instructions: Run all remaining code under the [ClassSchedule_9:15_Group1] database
USE [ClassSchedule_9:15_Group1];
GO
DROP SCHEMA IF EXISTS [Academic];
GO
CREATE SCHEMA [Academic];
GO
DROP SCHEMA IF EXISTS [Personnel];
GO
CREATE SCHEMA [Personnel];
GO
DROP SCHEMA IF EXISTS [ClassManagement];
GO
CREATE SCHEMA [ClassManagement];
GO
DROP SCHEMA IF EXISTS [Facilities];
GO
CREATE SCHEMA [Facilities];
GO
DROP SCHEMA IF EXISTS [Enrollment];
GO
CREATE SCHEMA [Enrollment];
GO
DROP SCHEMA IF EXISTS [DbSecurity];
GO
CREATE SCHEMA [DbSecurity];
GO
DROP SCHEMA IF EXISTS [Process];
GO
CREATE SCHEMA [Process];
GO
DROP SCHEMA IF EXISTS [PkSequence];
GO
CREATE SCHEMA [PkSequence];
GO
DROP SCHEMA IF EXISTS [Project3];
GO
CREATE SCHEMA [Project3];
GO
DROP SCHEMA IF EXISTS [G9_1];
GO
CREATE SCHEMA [G9_1];
GO
DROP SCHEMA IF EXISTS [Uploadfile]
GO
CREATE SCHEMA [Uploadfile]
GO
DROP SCHEMA IF EXISTS [Udt]
GO
CREATE SCHEMA [Udt]
GO
------------------------------------- Create User Defined Datatypes ---------------------------------------
--Aleks
CREATE TYPE [Udt].[DateAdded] FROM [datetime2] NOT NULL
GO
CREATE TYPE [Udt].[DateOfLastUpdate] FROM [datetime2] NOT NULL
GO
CREATE TYPE [Udt].[SurrogateKeyInt] FROM [int] NOT NULL
GO
CREATE TYPE [Udt].[ClassTime] FROM nchar(19) NOT NULL
GO
CREATE TYPE [Udt].[IndividualProject] FROM nvarchar (60) NOT NULL
GO
CREATE TYPE [Udt].[LastName] FROM nvarchar(35) NOT NULL
GO
CREATE TYPE [Udt].[FirstName] FROM nvarchar(20) NOT NULL
GO
CREATE TYPE [Udt].[GroupName] FROM nvarchar(20) NOT NULL
GO
CREATE TYPE [Udt].[CreditHours] FROM [FLOAT] NOT NULL
GO
-- Ahnaf
CREATE TYPE [Udt].[DayOfWeek] FROM CHAR(2) NULL
GO
-- Sigi
CREATE TYPE [Udt].SemesterName FROM NVARCHAR(20)
GO
-- Edwin
CREATE TYPE [Udt].[BuildingNameAbbrv] FROM NVARCHAR(3) NOT NULL;
GO
CREATE TYPE [Udt].[BuildingName] FROM NVARCHAR(50) NOT NULL;
GO
------------------------------------------ Import the UploadFile Data ---------------------------------------
-- Create the table
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Uploadfile].[CurrentSemesterCourseOfferings]
(
[Semester] [varchar](50) NULL,
[Sec] [varchar](50) NULL,
[Code] [varchar](50) NULL,
[Course (hr, crd)] [varchar](50) NULL,
[Description] [varchar](50) NULL,
[Day] [varchar](50) NULL,
[Time] [varchar](50) NULL,
[Instructor] [varchar](50) NULL,
[Location] [varchar](50) NULL,
[Enrolled] [varchar](50) NULL,
[Limit] [varchar](50) NULL,
[Mode of Instruction] [varchar](50) NULL
) ON [PRIMARY]
GO
ALTER TABLE [Uploadfile].[CurrentSemesterCourseOfferings] ADD CONSTRAINT [DF_CurrentSemesterCourseOfferings_Semester] DEFAULT ('Current Semester') FOR [Semester]
GO
INSERT INTO [ClassSchedule_9:15_Group1].[Uploadfile].[CurrentSemesterCourseOfferings]
(
[Semester],
[Sec],
[Code],
[Course (hr, crd)],
[Description],
[Day],
[Time],
[Instructor],
[Location],
[Enrolled],
[Limit],
[Mode of Instruction]
)
SELECT *
FROM [QueensClassSchedule].[UploadFile].[CurrentSemesterCourseOfferings]
GO
------------------------------------------- CREATE TABLES ----------------------------------------------
-- UserAuthorization Table --
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
DROP TABLE IF EXISTS [DbSecurity].[UserAuthorization]
GO
CREATE TABLE [DbSecurity].[UserAuthorization]
(
-- all tables must have the following 3 columns:
[UserAuthorizationKey] [Udt].[SurrogateKeyInt] NOT NULL IDENTITY(1,1), -- primary key
[DateAdded] [Udt].[DateAdded] NOT NULL,
[DateOfLastUpdate] [Udt].[DateOfLastUpdate] NOT NULL,
--
[ClassTime] [Udt].[ClassTime] NULL,
[IndividualProject] [Udt].[IndividualProject] NULL,
[GroupMemberLastName] [Udt].[LastName] NOT NULL,
[GroupMemberFirstName] [Udt].[FirstName] NOT NULL,
[GroupName] [nvarchar](20) NOT NULL
PRIMARY KEY CLUSTERED
(
[UserAuthorizationKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/*
Table: Process.[WorkflowSteps]
Description:
This table is used for auditing and tracking the execution of various workflow steps within the system.
It records key information about each workflow step, including a description, the number of rows affected,
the start and end times of the step, and the user who executed the step.
*/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
DROP TABLE IF EXISTS [Process].[WorkflowSteps]
GO
CREATE TABLE [Process].[WorkflowSteps]
(
[WorkFlowStepKey] [Udt].[SurrogateKeyInt] NOT NULL IDENTITY(1,1), -- primary key
[WorkFlowStepDescription] [nvarchar](100) NOT NULL,
[WorkFlowStepTableRowCount] [int] NULL,
[StartingDateTime] [datetime2](7) NULL,
[EndingDateTime] [datetime2](7) NULL,
[QueryTime (ms)] [bigint] NULL,
[Class Time] [char](5) NULL,
-- all tables must have the following 3 columns:
[UserAuthorizationKey] [Udt].[SurrogateKeyInt] NOT NULL,
[DateAdded] [Udt].[DateAdded] NOT NULL,
[DateOfLastUpdate] [Udt].[DateOfLastUpdate] NOT NULL,
PRIMARY KEY CLUSTERED(
[WorkFlowStepKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/*
Table: [Personnel].[Instructor]
-- =============================================
-- Author: Aleksandra Georgievska
-- Create date: 12/4/23
-- Description: Load the names & IDs into the user Instructor table
-- =============================================
*/
DROP TABLE IF EXISTS [Personnel].[Instructor]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Personnel].[Instructor]
(
InstructorID [int] NOT NULL IDENTITY(1, 1), -- primary key
FirstName [char](25) NULL,
LastName [char](25) NULL,
-- all tables must have the following 3 columns:
[UserAuthorizationKey] [Udt].[SurrogateKeyInt] NOT NULL,
[DateAdded] [Udt].[DateAdded] NOT NULL,
[DateOfLastUpdate] [Udt].[DateOfLastUpdate] NOT NULL,
PRIMARY KEY CLUSTERED(
[InstructorID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/*
Table: [Academic].[Course]
-- =============================================
-- Author: Aleksandra Georgievska
-- Create date: 12/5/23
-- Description: Load the Course Codes, Names, Credit/Course nums into the Course table
-- =============================================*/
DROP TABLE IF EXISTS [Academic].[Course]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Academic].[Course]
(
CourseId INT NOT NULL IDENTITY(1, 1), -- primary key
CourseAbbreviation CHAR(5) NOT NULL, -- needs check constraint
CourseNumber CHAR(5) NOT NULL,
CourseCredit FLOAT NOT NULL, -- (Needs Check Constraint to be positive)
CreditHours [Udt].[CreditHours] NOT NULL, -- CreditHours (Needs Check Constraint) -> should be positive, possibly a UDT
CourseName CHAR(35) NOT NULL, -- CourseDescription
DepartmentID [int] NOT NULL, -- FOREIGN KEY (DepartmentID) REFERENCES Department(DepartmentID)
-- all tables must have the following 3 columns:
[UserAuthorizationKey] [Udt].[SurrogateKeyInt] NOT NULL,
[DateAdded] [Udt].[DateAdded] NOT NULL,
[DateOfLastUpdate] [Udt].[DateOfLastUpdate] NOT NULL,
PRIMARY KEY CLUSTERED(
[CourseId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/*
Table: [Enrollment].[Semester]
-- =============================================
-- Author: Sigalita Yakubova
-- Create date: 12/4/23
-- Description: Showcase what semester belongs to each ID
-- =============================================
*/
DROP TABLE IF EXISTS [Enrollment].[Semester]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Enrollment].[Semester]
(
SemesterID [int] NOT NULL IDENTITY(1, 1), -- primary key
SemesterName [Udt].SemesterName NULL,
-- all tables must have the following 3 columns:
[UserAuthorizationKey] [Udt].[SurrogateKeyInt] NOT NULL,
[DateAdded] [Udt].[DateAdded] NOT NULL,
[DateOfLastUpdate] [Udt].[DateOfLastUpdate] NOT NULL,
PRIMARY KEY CLUSTERED(
[SemesterID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/*
--Table: [ClassManagement].[ModeOfInstruction]
-- =============================================
-- Author: Nicholas Kong
-- Create date: 12/4/23
-- Description: Load the names & IDs into the user ModeOfInstruction table
-- =============================================
*/
DROP TABLE IF EXISTS [ClassManagement].[ModeOfInstruction]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [ClassManagement].[ModeOfInstruction] (
ModeID INT IDENTITY (1,1) NOT NULL,
ModeName NVARCHAR(12) NOT NULL,
-- all tables must have the following 3 columns:
[UserAuthorizationKey] [Udt].[SurrogateKeyInt] NOT NULL,
[DateAdded] [Udt].[DateAdded] NOT NULL,
[DateOfLastUpdate] [Udt].[DateOfLastUpdate] NOT NULL,
PRIMARY KEY CLUSTERED(
[ModeID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
-- Nicholas
DROP TABLE IF EXISTS [Facilities].[RoomLocation]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Facilities].[RoomLocation] (
RoomID INT IDENTITY(1,1) NOT NULL,
RoomNumber VARCHAR(12) NULL,
BuildingCode INT, -- Assuming BuildingCode is INT; adjust the data type as needed
-- FOREIGN KEY (BuildingCode) REFERENCES BuildingLocation(BuildingCode),
-- all tables must have the following 3 columns:
[UserAuthorizationKey] [Udt].[SurrogateKeyInt] NOT NULL,
[DateAdded] [Udt].[DateAdded] NOT NULL,
[DateOfLastUpdate] [Udt].[DateOfLastUpdate] NOT NULL,
PRIMARY KEY CLUSTERED(
[RoomID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
-- Nicholas
DROP TABLE IF EXISTS [ClassManagement].[Schedule]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [ClassManagement].[Schedule] (
ScheduleID INT IDENTITY(1,1) NOT NULL,
RoomID INT NULL,
SectionID INT NULL,
ClassID INT NULL,
SemesterID INT NULL,
StartTimeRange [Udt].[ClassTime] NOT NULL CHECK (StartTimeRange >= '00:00:00.0000000' AND StartTimeRange <= '24:00:00.0000000'),
EndTimeRange [Udt].[ClassTime] NOT NULL CHECK (EndTimeRange >= '00:00:00.0000000' AND EndTimeRange <= '24:00:00.0000000'),
-- all tables must have the following 3 columns:
[UserAuthorizationKey] [Udt].[SurrogateKeyInt] NOT NULL,
[DateAdded] [Udt].[DateAdded] NOT NULL,
[DateOfLastUpdate] [Udt].[DateOfLastUpdate] NOT NULL,
PRIMARY KEY CLUSTERED(
[ScheduleID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
-- Ahnaf
/*
Table: [ClassManagement].[Days]
-- =============================================
-- Author: Ahnaf Ahmed
-- Create date: 12/4/23
-- Description: Table to store all days of the week to be later used for classdays bridge table
-- =============================================
*/
DROP TABLE IF EXISTS [ClassManagement].[Days]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [ClassManagement].[Days]
(
[DayID] [int] NOT NULL IDENTITY(1, 1), -- primary key
[DayAbbreviation] [Udt].[DayOfWeek] NOT NULL,
-- all tables must have the following 3 columns:
[UserAuthorizationKey] [Udt].[SurrogateKeyInt] NOT NULL,
[DateAdded] [Udt].[DateAdded] NOT NULL,
[DateOfLastUpdate] [Udt].[DateOfLastUpdate] NOT NULL,
PRIMARY KEY CLUSTERED(
[DayID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/*
Table: [Academic].[Department]
-- =============================================
-- Author: Aryeh Richman
-- Create date: 12/5/23
-- Description: Create a Department table with id and name
-- =============================================
*/
DROP TABLE IF EXISTS [Academic].[Department]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Academic].[Department]
(
DepartmentID [int] NOT NULL IDENTITY(1, 1), -- primary key
DepartmentName [char](5) NOT NULL,
-- all tables must have the following 3 columns:
[UserAuthorizationKey] [Udt].[SurrogateKeyInt] NOT NULL,
[DateAdded] [Udt].[DateAdded] NOT NULL,
[DateOfLastUpdate] [Udt].[DateOfLastUpdate] NOT NULL,
PRIMARY KEY CLUSTERED(
[DepartmentID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/*
Table: [Personnel].[DepartmentInstructor]
-- =============================================
-- Author: Aryeh Richman
-- Create date: 12/6/23
-- Description: Create a bridge table between departments and instructors
-- =============================================
*/
DROP TABLE IF EXISTS [Personnel].[DepartmentInstructor]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Personnel].[DepartmentInstructor]
(
DepartmentInstructorID [int] NOT NULL IDENTITY(1, 1), -- primary key
DepartmentID [int] NOT NULL,
InstructorID [int] NOT NULL,
-- all tables must have the following 3 columns:
[UserAuthorizationKey] [Udt].[SurrogateKeyInt] NOT NULL,
[DateAdded] [Udt].[DateAdded] NOT NULL,
[DateOfLastUpdate] [Udt].[DateOfLastUpdate] NOT NULL,
PRIMARY KEY CLUSTERED(
[DepartmentInstructorID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/*
Table: [ClassManagement].[ClassDays]
-- =============================================
-- Author: Aryeh Richman
-- Create date: 12/6/23
-- Description: Create a bridge table between class and days
-- =============================================
*/
DROP TABLE IF EXISTS [ClassManagement].[ClassDays]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [ClassManagement].[ClassDays]
(
ClassDaysID [int] NOT NULL IDENTITY(1, 1), -- primary key
ClassID [int] NOT NULL,
DayID [int] NOT NULL,
-- all tables must have the following 3 columns:
[UserAuthorizationKey] [Udt].[SurrogateKeyInt] NOT NULL,
[DateAdded] [Udt].[DateAdded] NOT NULL,
[DateOfLastUpdate] [Udt].[DateOfLastUpdate] NOT NULL,
PRIMARY KEY CLUSTERED(
[ClassDaysID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/*
Table: [Facilities].[BuildingLocations]
-- =============================================
-- Author: Edwin Wray
-- Create date: 12/5/23
-- Description: Create BuildingLocations table with building id and names
-- =============================================
*/
DROP TABLE IF EXISTS [Facilities].[BuildingLocations]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Facilities].[BuildingLocations]
(
BuildingID [int] NOT NULL IDENTITY(1, 1), -- primary key
BuildingNameAbbrv [Udt].[BuildingNameAbbrv] NOT NULL,
BuildingName [Udt].[BuildingName] NOT NULL,
-- all tables must have the following 3 columns:
[UserAuthorizationKey] [Udt].[SurrogateKeyInt] NOT NULL,
[DateAdded] [Udt].[DateAdded] NOT NULL,
[DateOfLastUpdate] [Udt].[DateOfLastUpdate] NOT NULL,
PRIMARY KEY CLUSTERED(
[BuildingID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/*
Table: [ClassManagement].[Class]
-- =============================================
-- Author: Edwin Wray
-- Create date: 12/7/23
-- Description: Create Class table
-- =============================================
*/
DROP TABLE IF EXISTS [ClassManagement].[Class]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [ClassManagement].[Class]
(
ClassID [int] NOT NULL IDENTITY(1, 1), -- primary key
CourseID [int] NOT NULL,
SectionID [int] NOT NULL,
InstructorID [int] NOT NULL,
RoomID [int] NOT NULL,
ModeID [int] NOT NULL,
-- all tables must have the following 3 columns:
[UserAuthorizationKey] [Udt].[SurrogateKeyInt] NOT NULL,
[DateAdded] [Udt].[DateAdded] NOT NULL,
[DateOfLastUpdate] [Udt].[DateOfLastUpdate] NOT NULL,
PRIMARY KEY CLUSTERED(
[ClassID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/*
Table: [Academic].[Section]
-- =============================================
-- Author: Sigalita Yakubova
-- Create date: 12/7/2023
-- Description: Load the Section Codes into the Section table
-- =============================================*/
DROP TABLE IF EXISTS [Academic].[Section]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Academic].[Section]
(
SectionID INT NOT NULL IDENTITY(1, 1), -- primary key
Section varchar(20) NOT NULL,
Code varchar(20) NOT NULL,
CourseID [int] NOT NULL, -- FOREIGN KEY (CourseID)
-- all tables must have the following 3 columns:
[UserAuthorizationKey] [Udt].[SurrogateKeyInt] NOT NULL,
[DateAdded] [Udt].[DateAdded] NOT NULL,
[DateOfLastUpdate] [Udt].[DateOfLastUpdate] NOT NULL,
PRIMARY KEY CLUSTERED(
[SectionId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/*
Table: [Enrollment].[EnrollmentDetail]
-- =============================================
-- Author: Ahnaf Ahmed
-- Create date: 12/8/23
-- Description: Create table to store enrollment details for each section
-- =============================================
*/
DROP TABLE IF EXISTS [Enrollment].[EnrollmentDetail]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Enrollment].[EnrollmentDetail]
(
[EnrollmentID] INT NOT NULL IDENTITY(1, 1), -- primary key
[SectionID] INT NOT NULL, -- Foreign Key (SectionID)
[CurrentEnrollment] INT NOT NULL,
[MaxEnrollmentLimit] INT NOT NULL,
[OverEnrolled] NCHAR(3),
-- all tables must have the following 3 columns:
[UserAuthorizationKey] [Udt].[SurrogateKeyInt] NOT NULL,
[DateAdded] [Udt].[DateAdded] NOT NULL,
[DateOfLastUpdate] [Udt].[DateOfLastUpdate] NOT NULL,
PRIMARY KEY CLUSTERED(
[EnrollmentID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
--------------------- Alter Tables To Update Defaults/Constraints -------------------
-- Aleks
ALTER TABLE [DbSecurity].[UserAuthorization] ADD DEFAULT ('9:15') FOR [ClassTime]
GO
ALTER TABLE [DbSecurity].[UserAuthorization] ADD DEFAULT ('PROJECT 3') FOR [IndividualProject]
GO
ALTER TABLE [DbSecurity].[UserAuthorization] ADD DEFAULT ('GROUP 1') FOR [GroupName]
GO
ALTER TABLE [DbSecurity].[UserAuthorization] ADD DEFAULT (sysdatetime()) FOR [DateAdded]
GO
ALTER TABLE [DbSecurity].[UserAuthorization] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate]
GO
ALTER TABLE [Process].[WorkflowSteps] ADD DEFAULT ((0)) FOR [WorkFlowStepTableRowCount]
GO
ALTER TABLE [Process].[WorkflowSteps] ADD DEFAULT ('09:15') FOR [Class Time]
GO
ALTER TABLE [Process].[WorkflowSteps] ADD DEFAULT (sysdatetime()) FOR [StartingDateTime]
GO
ALTER TABLE [Process].[WorkflowSteps] ADD DEFAULT (sysdatetime()) FOR [EndingDateTime]
GO
ALTER TABLE [Process].[WorkflowSteps] ADD DEFAULT (sysdatetime()) FOR [DateAdded]
GO
ALTER TABLE [Process].[WorkflowSteps] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate]
GO
ALTER TABLE [Personnel].[Instructor] ADD DEFAULT (sysdatetime()) FOR [DateAdded]
GO
ALTER TABLE [Personnel].[Instructor] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate]
GO
ALTER TABLE [Personnel].[Instructor] ADD DEFAULT ('none') FOR [LastName]
GO
ALTER TABLE [Personnel].[Instructor] ADD DEFAULT ('none') FOR [FirstName]
GO
ALTER TABLE [Academic].[Course] ADD DEFAULT (sysdatetime()) FOR [DateAdded]
GO
ALTER TABLE [Academic].[Course] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate]
GO
ALTER TABLE [Academic].[Course] ADD DEFAULT ('unknown') FOR [CourseName]
GO
-- Ahnaf
ALTER TABLE [ClassManagement].[Days] ADD DEFAULT (sysdatetime()) FOR [DateAdded]
GO
ALTER TABLE [ClassManagement].[Days] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate]
GO
ALTER TABLE [Enrollment].[EnrollmentDetail] ADD DEFAULT (sysdatetime()) FOR [DateAdded]
GO
ALTER TABLE [Enrollment].[EnrollmentDetail] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate]
GO
-- Nicholas
ALTER TABLE [ClassManagement].[ModeOfInstruction] ADD DEFAULT (sysdatetime()) FOR [DateAdded]
GO
ALTER TABLE [ClassManagement].[ModeOfInstruction] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate]
GO
ALTER TABLE [Facilities].[RoomLocation] ADD DEFAULT (sysdatetime()) FOR [DateAdded]
GO
ALTER TABLE [Facilities].[RoomLocation] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate]
GO
ALTER TABLE [ClassManagement].[Schedule] ADD DEFAULT (sysdatetime()) FOR [DateAdded]
GO
ALTER TABLE [ClassManagement].[Schedule] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate]
GO
--Sigi
ALTER TABLE [Enrollment].[Semester] ADD DEFAULT (sysdatetime()) FOR [DateAdded]
GO
ALTER TABLE [Enrollment].[Semester] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate]
GO
ALTER TABLE [Academic].[Section] ADD DEFAULT (sysdatetime()) FOR [DateAdded]
GO
ALTER TABLE [Academic].[Section] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate]
GO
-- Aryeh
ALTER TABLE [Academic].[Department] ADD DEFAULT (sysdatetime()) FOR [DateAdded]
GO
ALTER TABLE [Academic].[Department] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate]
GO
ALTER TABLE [Personnel].[DepartmentInstructor] ADD DEFAULT (sysdatetime()) FOR [DateAdded]
GO
ALTER TABLE [Personnel].[DepartmentInstructor] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate]
GO
ALTER TABLE [ClassManagement].[ClassDays] ADD DEFAULT (sysdatetime()) FOR [DateAdded]
GO
ALTER TABLE [ClassManagement].[ClassDays] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate]
GO
-- Edwin
ALTER TABLE [Facilities].[BuildingLocations] ADD DEFAULT (sysdatetime()) FOR [DateAdded]
GO
ALTER TABLE [Facilities].[BuildingLocations] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate]
GO
ALTER TABLE [ClassManagement].[Class] ADD DEFAULT (sysdatetime()) FOR [DateAdded]
GO
ALTER TABLE [ClassManagement].[Class] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate]
GO
-- add check constraints in the following format:
-- Aleks
ALTER TABLE [Process].[WorkflowSteps] WITH CHECK ADD CONSTRAINT [FK_WorkFlowSteps_UserAuthorization] FOREIGN KEY([UserAuthorizationKey])
REFERENCES [DbSecurity].[UserAuthorization] ([UserAuthorizationKey])
GO
ALTER TABLE [Process].[WorkflowSteps] CHECK CONSTRAINT [FK_WorkFlowSteps_UserAuthorization]
GO
ALTER TABLE [Personnel].[Instructor] WITH CHECK ADD CONSTRAINT [FK_Instructor_UserAuthorization] FOREIGN KEY([UserAuthorizationKey])
REFERENCES [DbSecurity].[UserAuthorization] ([UserAuthorizationKey])
GO
ALTER TABLE [Personnel].[Instructor] CHECK CONSTRAINT [FK_Instructor_UserAuthorization]
GO
ALTER TABLE [Academic].[Course] WITH CHECK ADD CONSTRAINT [FK_Course_DepartmentID] FOREIGN KEY([DepartmentID])
REFERENCES [Academic].[Department] ([DepartmentID])
GO
ALTER TABLE [Academic].[Course] WITH CHECK ADD CONSTRAINT [FK_Course_UserAuthorization] FOREIGN KEY([UserAuthorizationKey])
REFERENCES [DbSecurity].[UserAuthorization] ([UserAuthorizationKey])
GO
ALTER TABLE [Academic].[Course] CHECK CONSTRAINT [FK_Course_UserAuthorization]
GO
ALTER TABLE [Academic].[Course] ADD CONSTRAINT [CHK_CreditHours_Positive] CHECK (CreditHours >= 0)
GO
ALTER TABLE [Academic].[Course] ADD CONSTRAINT [CHK_CourseCredit_Positive] CHECK (CourseCredit >= 0)
GO
--Sigi
ALTER TABLE [Enrollment].[Semester] WITH CHECK ADD CONSTRAINT [FK_Semester_UserAuthorization] FOREIGN KEY([UserAuthorizationKey])
REFERENCES [DbSecurity].[UserAuthorization] ([UserAuthorizationKey])
GO
ALTER TABLE [Enrollment].[Semester] CHECK CONSTRAINT [FK_Semester_UserAuthorization]
GO
ALTER TABLE [Academic].[Section] WITH CHECK ADD CONSTRAINT [FK_Section_Course] FOREIGN KEY([CourseId])
REFERENCES [Academic].[Course] ([CourseId])
GO
ALTER TABLE [Academic].[Section] WITH CHECK ADD CONSTRAINT [FK_Section_UserAuthorization] FOREIGN KEY([UserAuthorizationKey])
REFERENCES [DbSecurity].[UserAuthorization] ([UserAuthorizationKey])
GO
ALTER TABLE [Academic].[Section] CHECK CONSTRAINT [FK_Section_UserAuthorization]
GO
-- Ahnaf
ALTER TABLE [ClassManagement].[Days] WITH CHECK ADD CONSTRAINT [FK_Days_UserAuthorization] FOREIGN KEY([UserAuthorizationKey])
REFERENCES [DbSecurity].[UserAuthorization] ([UserAuthorizationKey])
GO
ALTER TABLE [ClassManagement].[Days] CHECK CONSTRAINT [FK_Days_UserAuthorization]
GO
ALTER TABLE [ClassManagement].[Days] ADD CONSTRAINT CHK_DayOfWeek
CHECK (DayAbbreviation IN ('M', 'T', 'W', 'TH', 'F', 'S', 'SU'))
GO
ALTER TABLE [Enrollment].[EnrollmentDetail] WITH CHECK ADD CONSTRAINT [FK_EnrollmentDetail_UserAuthorization] FOREIGN KEY([UserAuthorizationKey])
REFERENCES [DbSecurity].[UserAuthorization] ([UserAuthorizationKey])
GO
ALTER TABLE [Enrollment].[EnrollmentDetail] CHECK CONSTRAINT [FK_EnrollmentDetail_UserAuthorization]
GO
ALTER TABLE [Enrollment].[EnrollmentDetail] WITH CHECK ADD CONSTRAINT [FK_EnrollmentDetail_Section] FOREIGN KEY([SectionID])
REFERENCES [Academic].[Section] ([SectionID])
GO
ALTER TABLE [Enrollment].[EnrollmentDetail] CHECK CONSTRAINT [FK_EnrollmentDetail_Section]
GO
-- Nicholas
ALTER TABLE [ClassManagement].[ModeOfInstruction] WITH CHECK ADD CONSTRAINT [FK_ModeOfInst_UserAuthorization] FOREIGN KEY([UserAuthorizationKey])
REFERENCES [DbSecurity].[UserAuthorization] ([UserAuthorizationKey])
GO
ALTER TABLE [ClassManagement].[ModeOfInstruction] CHECK CONSTRAINT [FK_ModeOfInst_UserAuthorization]
GO
ALTER TABLE [Facilities].[RoomLocation] WITH CHECK ADD CONSTRAINT [FK_RoomLocation_UserAuthorization] FOREIGN KEY([UserAuthorizationKey])
REFERENCES [DbSecurity].[UserAuthorization] ([UserAuthorizationKey])
GO
ALTER TABLE [Facilities].[RoomLocation] CHECK CONSTRAINT [FK_RoomLocation_UserAuthorization]
GO
ALTER TABLE [ClassManagement].[Schedule] WITH CHECK ADD CONSTRAINT [FK_Schedule_UserAuthorization] FOREIGN KEY([UserAuthorizationKey])
REFERENCES [DbSecurity].[UserAuthorization] ([UserAuthorizationKey])
GO
ALTER TABLE [ClassManagement].[Schedule] CHECK CONSTRAINT [FK_Schedule_UserAuthorization]
GO
ALTER TABLE [ClassManagement].[Schedule] WITH CHECK ADD CONSTRAINT [FK_Schedule_RoomLocation] FOREIGN KEY([RoomID])
REFERENCES [Facilities].[RoomLocation] ([RoomID])
GO
ALTER TABLE [ClassManagement].[Schedule] WITH CHECK ADD CONSTRAINT [FK_Schedule_Section] FOREIGN KEY([SectionID])
REFERENCES [Academic].[Section] ([SectionID])
GO
ALTER TABLE [ClassManagement].[Schedule] WITH CHECK ADD CONSTRAINT [FK_Schedule_Class] FOREIGN KEY([ClassID])
REFERENCES [ClassManagement].[Class] ([ClassID])
GO
ALTER TABLE [ClassManagement].[Schedule] WITH CHECK ADD CONSTRAINT [FK_Schedule_Semester] FOREIGN KEY([SemesterID])
REFERENCES [Enrollment].[Semester] ([SemesterID])
GO
-- Aryeh
ALTER TABLE [Academic].[Department] WITH CHECK ADD CONSTRAINT [FK_Department_UserAuthorization] FOREIGN KEY([UserAuthorizationKey])
REFERENCES [DbSecurity].[UserAuthorization] ([UserAuthorizationKey])
GO
ALTER TABLE [Academic].[Department] CHECK CONSTRAINT [FK_Department_UserAuthorization]
GO
ALTER TABLE [Personnel].[DepartmentInstructor] WITH CHECK ADD CONSTRAINT [FK_DepartmentInstructor_UserAuthorization] FOREIGN KEY([UserAuthorizationKey])
REFERENCES [DbSecurity].[UserAuthorization] ([UserAuthorizationKey])
GO
ALTER TABLE [Personnel].[DepartmentInstructor] CHECK CONSTRAINT [FK_DepartmentInstructor_UserAuthorization]
GO
ALTER TABLE [Personnel].[DepartmentInstructor] WITH CHECK ADD CONSTRAINT [FK_DepartmentInstructor_Department] FOREIGN KEY([DepartmentID])
REFERENCES [Academic].[Department] ([DepartmentID])
GO
ALTER TABLE [Personnel].[DepartmentInstructor] CHECK CONSTRAINT [FK_DepartmentInstructor_Department]
GO
ALTER TABLE [ClassManagement].[ClassDays] WITH CHECK ADD CONSTRAINT [FK_ClassDays_UserAuthorization] FOREIGN KEY([UserAuthorizationKey])
REFERENCES [DbSecurity].[UserAuthorization] ([UserAuthorizationKey])
GO
ALTER TABLE [ClassManagement].[ClassDays] CHECK CONSTRAINT [FK_ClassDays_UserAuthorization]
GO
ALTER TABLE [ClassManagement].[ClassDays] WITH CHECK ADD CONSTRAINT [FK_ClassDays_Class] FOREIGN KEY([ClassID])
REFERENCES [ClassManagement].[Class] ([ClassID])
GO
ALTER TABLE [ClassManagement].[ClassDays] CHECK CONSTRAINT [FK_ClassDays_Class]
GO
ALTER TABLE [ClassManagement].[ClassDays] WITH CHECK ADD CONSTRAINT [FK_ClassDays_Days] FOREIGN KEY([DayID])
REFERENCES [ClassManagement].[Days] ([DayID])
GO
ALTER TABLE [ClassManagement].[ClassDays] CHECK CONSTRAINT [FK_ClassDays_Days]
GO
-- Edwin
ALTER TABLE [Facilities].[BuildingLocations] WITH CHECK ADD CONSTRAINT [FK_BuildingLocations_UserAuthorization] FOREIGN KEY([UserAuthorizationKey])
REFERENCES [DbSecurity].[UserAuthorization] ([UserAuthorizationKey])
GO
ALTER TABLE [Facilities].[BuildingLocations] CHECK CONSTRAINT [FK_BuildingLocations_UserAuthorization]
GO
ALTER TABLE [ClassManagement].[Class] WITH CHECK ADD CONSTRAINT [FK_Class_UserAuthorization] FOREIGN KEY([UserAuthorizationKey])
REFERENCES [DbSecurity].[UserAuthorization] ([UserAuthorizationKey])
GO
ALTER TABLE [ClassManagement].[Class] CHECK CONSTRAINT [FK_Class_UserAuthorization]
GO
ALTER TABLE [ClassManagement].[Class] WITH CHECK ADD CONSTRAINT [FK_Class_Course] FOREIGN KEY([CourseID])
REFERENCES [Academic].[Course] ([CourseID])
GO
ALTER TABLE [ClassManagement].[Class] CHECK CONSTRAINT [FK_Class_Course]
GO
ALTER TABLE [ClassManagement].[Class] WITH CHECK ADD CONSTRAINT [FK_Class_Section] FOREIGN KEY([SectionID])
REFERENCES [Academic].[Section] ([SectionID])
GO
ALTER TABLE [ClassManagement].[Class] CHECK CONSTRAINT [FK_Class_Section]
GO
ALTER TABLE [ClassManagement].[Class] WITH CHECK ADD CONSTRAINT [FK_Class_Instructor] FOREIGN KEY([InstructorID])
REFERENCES [Personnel].[Instructor] ([InstructorID])
GO
ALTER TABLE [ClassManagement].[Class] CHECK CONSTRAINT [FK_Class_Instructor]
GO
ALTER TABLE [ClassManagement].[Class] WITH CHECK ADD CONSTRAINT [FK_Class_RoomLocation] FOREIGN KEY([RoomID])
REFERENCES [Facilities].[RoomLocation] ([RoomID])
GO
ALTER TABLE [ClassManagement].[Class] CHECK CONSTRAINT [FK_Class_RoomLocation]
GO
ALTER TABLE [ClassManagement].[Class] WITH CHECK ADD CONSTRAINT [FK_Class_ModeOfInstruction] FOREIGN KEY([ModeID])
REFERENCES [ClassManagement].[ModeOfInstruction] ([ModeID])
GO
ALTER TABLE [ClassManagement].[Class] CHECK CONSTRAINT [FK_Class_ModeOfInstruction]
GO
--------------------------------- CREATE FUNCTIONS --------------------------------
-- Sigi
-- Create a function to determine the season
CREATE FUNCTION [Udt].GetSeason(@DateAdded DATETIME2)
RETURNS NVARCHAR(10)
AS
BEGIN
DECLARE @Season NVARCHAR(10);
SET @Season =
CASE
WHEN MONTH(@DateAdded) BETWEEN 1 AND 3 THEN 'Winter'
WHEN MONTH(@DateAdded) BETWEEN 4 AND 6 THEN 'Spring'
WHEN MONTH(@DateAdded) BETWEEN 7 AND 9 THEN 'Summer'
WHEN MONTH(@DateAdded) BETWEEN 10 AND 12 THEN 'Fall'
END;
RETURN @Season;
END;
GO
-- Create a function to get the formatted SemesterName
CREATE FUNCTION [Udt].GetSemesterName(@DateAdded DATETIME2)
RETURNS [Udt].SemesterName
AS
BEGIN
DECLARE @Season NVARCHAR(10);
DECLARE @Year NVARCHAR(4);
DECLARE @SemesterName [Udt].SemesterName;
SET @Season = [Udt].GetSeason(@DateAdded);
SET @Year = FORMAT(@DateAdded, 'yyyy');
SET @SemesterName = @Season + ' ' + @Year;
RETURN @SemesterName;
END;
GO
--Edwin
-- Create a function to determine the BuildingName
CREATE FUNCTION [Udt].[GetBuildingNameAbbrv](@Location VARCHAR(50))
RETURNS [Udt].[BuildingNameAbbrv]
AS
BEGIN
IF @Location IS NULL OR LTRIM(RTRIM(@Location)) = ''
RETURN 'TBD';