-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeployment 4-18-18.sql
More file actions
1423 lines (1147 loc) · 84.5 KB
/
Deployment 4-18-18.sql
File metadata and controls
1423 lines (1147 loc) · 84.5 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
GO
/****** Object: Table [dbo].[Center] Script Date: 4/18/2018 9:16:23 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Center](
[CenterID] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NOT NULL,
[County] [nvarchar](50) NOT NULL,
[Region] [nvarchar](50) NOT NULL,
CONSTRAINT [PK_Center] PRIMARY KEY CLUSTERED
(
[CenterID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
GO
/****** Object: Table [dbo].[CertCompletion] Script Date: 4/18/2018 9:16:23 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CertCompletion](
[StaffMemberID] [int] NOT NULL,
[CertificationID] [int] NOT NULL,
[CertCompletionDate] [date] NULL,
[CertInProgress] [bit] NOT NULL,
CONSTRAINT [PK_CertCompletion] PRIMARY KEY CLUSTERED
(
[StaffMemberID] ASC,
[CertificationID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
GO
/****** Object: Table [dbo].[Certification] Script Date: 4/18/2018 9:16:23 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Certification](
[CertificationID] [int] IDENTITY(1,1) NOT NULL,
[CertName] [nvarchar](50) NULL,
[CertExpireAmount] [int] NULL,
CONSTRAINT [PK_Certification] PRIMARY KEY CLUSTERED
(
[CertificationID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
GO
/****** Object: Table [dbo].[ECSUser] Script Date: 4/18/2018 9:16:23 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ECSUser](
[UserID] [int] IDENTITY(1,1) NOT NULL,
[Email] [varchar](150) NOT NULL,
[FirstName] [varchar](50) NULL,
[LastName] [varchar](50) NULL,
[AccessLevel] [int] NOT NULL,
[PasswordHash] [varchar](128) NOT NULL,
CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED
(
[UserID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
GO
/****** Object: Table [dbo].[Education] Script Date: 4/18/2018 9:16:23 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Education](
[EducationID] [int] IDENTITY(1,1) NOT NULL,
[DegreeAbrv] [nvarchar](50) NULL,
[DegreeLevel] [nvarchar](50) NULL,
[DegreeType] [nvarchar](50) NULL,
[DegreeDetail] [nvarchar](50) NULL,
CONSTRAINT [PK_Education] PRIMARY KEY CLUSTERED
(
[EducationID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
GO
/****** Object: Table [dbo].[Position] Script Date: 4/18/2018 9:16:23 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Position](
[PositionID] [int] IDENTITY(1,1) NOT NULL,
[PositionTitle] [nvarchar](50) NULL,
CONSTRAINT [PK_Position] PRIMARY KEY CLUSTERED
(
[PositionID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
GO
/****** Object: Table [dbo].[PositionReq] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PositionReq](
[PositionID] [int] NOT NULL,
[CertificationID] [int] NOT NULL,
CONSTRAINT [PK_PostionReq] PRIMARY KEY CLUSTERED
(
[PositionID] ASC,
[CertificationID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
GO
/****** Object: Table [dbo].[StaffEducation] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[StaffEducation](
[StaffMemberID] [int] NOT NULL,
[EducationID] [int] NOT NULL,
CONSTRAINT [PK_StaffEducation] PRIMARY KEY CLUSTERED
(
[StaffMemberID] ASC,
[EducationID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
GO
/****** Object: Table [dbo].[StaffMember] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[StaffMember](
[StaffMemberID] [int] IDENTITY(1,1) NOT NULL,
[FirstName] [nvarchar](50) NULL,
[LastName] [nvarchar](50) NULL,
[Email] [nvarchar](50) NULL,
[DateOfHire] [date] NULL,
[CenterID] [int] NULL,
[DirectorCredentials] [bit] NULL,
[DCExpiration] [date] NULL,
[CDAInProgress] [bit] NULL,
[CDAType] [nvarchar](50) NULL,
[CDAExpiration] [date] NULL,
[CDARenewalProcess] [nvarchar](50) NULL,
[Comments] [nvarchar](150) NULL,
[Goal] [bit] NULL,
[MidYear] [bit] NULL,
[EndYear] [bit] NULL,
[GoalMet] [bit] NULL,
[TAndAApp] [bit] NULL,
[AppApp] [bit] NULL,
[ClassCompleted] [bit] NULL,
[ClassPaid] [bit] NULL,
[RequiredHours] [int] NULL,
[HoursEarned] [int] NULL,
[Notes] [nvarchar](200) NULL,
[TermDate] [date] NULL,
[IsInactive] [bit] NULL,
CONSTRAINT [PK__StaffMem__2C1EBDA1C3E4047E] PRIMARY KEY CLUSTERED
(
[StaffMemberID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
GO
/****** Object: Table [dbo].[StaffPosition] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[StaffPosition](
[StaffMemberID] [int] NOT NULL,
[PositionID] [int] NOT NULL,
CONSTRAINT [PK_StaffPosition] PRIMARY KEY CLUSTERED
(
[StaffMemberID] ASC,
[PositionID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
GO
/****** Object: Table [dbo].[sysdiagrams] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[sysdiagrams](
[name] [sysname] NOT NULL,
[principal_id] [int] NOT NULL,
[diagram_id] [int] IDENTITY(1,1) NOT NULL,
[version] [int] NULL,
[definition] [varbinary](max) NULL,
PRIMARY KEY CLUSTERED
(
[diagram_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON),
CONSTRAINT [UK_principal_name] UNIQUE NONCLUSTERED
(
[principal_id] ASC,
[name] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
GO
ALTER TABLE [dbo].[Center] ADD CONSTRAINT [DF_Center_Name] DEFAULT (NULL) FOR [Name]
GO
ALTER TABLE [dbo].[Center] ADD CONSTRAINT [DF_Center_County] DEFAULT (NULL) FOR [County]
GO
ALTER TABLE [dbo].[Center] ADD CONSTRAINT [DF_Center_Region] DEFAULT (NULL) FOR [Region]
GO
ALTER TABLE [dbo].[StaffMember] ADD CONSTRAINT [DF_StaffMember_Email] DEFAULT (NULL) FOR [Email]
GO
ALTER TABLE [dbo].[StaffMember] ADD CONSTRAINT [DF_StaffMember_DateOfHire] DEFAULT (NULL) FOR [DateOfHire]
GO
ALTER TABLE [dbo].[StaffMember] ADD CONSTRAINT [DF_StaffMember_DirectorCredentials] DEFAULT ((0)) FOR [DirectorCredentials]
GO
ALTER TABLE [dbo].[StaffMember] ADD CONSTRAINT [DF_StaffMember_DCExpiration] DEFAULT (NULL) FOR [DCExpiration]
GO
ALTER TABLE [dbo].[StaffMember] ADD CONSTRAINT [DF_StaffMember_CDAInProgress] DEFAULT ((0)) FOR [CDAInProgress]
GO
ALTER TABLE [dbo].[StaffMember] ADD CONSTRAINT [DF_StaffMember_CDAType] DEFAULT (NULL) FOR [CDAType]
GO
ALTER TABLE [dbo].[StaffMember] ADD CONSTRAINT [DF_StaffMember_CDAExpiration] DEFAULT (NULL) FOR [CDAExpiration]
GO
ALTER TABLE [dbo].[StaffMember] ADD CONSTRAINT [DF_StaffMember_CDARenewalProcess] DEFAULT (NULL) FOR [CDARenewalProcess]
GO
ALTER TABLE [dbo].[StaffMember] ADD CONSTRAINT [DF_StaffMember_Comments] DEFAULT (NULL) FOR [Comments]
GO
ALTER TABLE [dbo].[StaffMember] ADD CONSTRAINT [DF_StaffMember_Goal] DEFAULT (NULL) FOR [Goal]
GO
ALTER TABLE [dbo].[StaffMember] ADD CONSTRAINT [DF_StaffMember_MidYear] DEFAULT (NULL) FOR [MidYear]
GO
ALTER TABLE [dbo].[StaffMember] ADD CONSTRAINT [DF_StaffMember_EndYear] DEFAULT (NULL) FOR [EndYear]
GO
ALTER TABLE [dbo].[StaffMember] ADD CONSTRAINT [DF_StaffMember_GoalMet] DEFAULT ((0)) FOR [GoalMet]
GO
ALTER TABLE [dbo].[StaffMember] ADD CONSTRAINT [DF_StaffMember_TAndAApp] DEFAULT (NULL) FOR [TAndAApp]
GO
ALTER TABLE [dbo].[StaffMember] ADD CONSTRAINT [DF_StaffMember_AppApp] DEFAULT (NULL) FOR [AppApp]
GO
ALTER TABLE [dbo].[StaffMember] ADD CONSTRAINT [DF_StaffMember_ClassCompleted] DEFAULT (NULL) FOR [ClassCompleted]
GO
ALTER TABLE [dbo].[StaffMember] ADD CONSTRAINT [DF_StaffMember_ClassPaid] DEFAULT ((0)) FOR [ClassPaid]
GO
ALTER TABLE [dbo].[StaffMember] ADD CONSTRAINT [DF_StaffMember_RequiredHours] DEFAULT ((0)) FOR [RequiredHours]
GO
ALTER TABLE [dbo].[StaffMember] ADD CONSTRAINT [DF_StaffMember_HoursEarned] DEFAULT ((0)) FOR [HoursEarned]
GO
ALTER TABLE [dbo].[StaffMember] ADD CONSTRAINT [DF_StaffMember_Notes] DEFAULT (NULL) FOR [Notes]
GO
ALTER TABLE [dbo].[StaffMember] ADD CONSTRAINT [DF_StaffMember_TermDate] DEFAULT (NULL) FOR [TermDate]
GO
ALTER TABLE [dbo].[PositionReq] WITH CHECK ADD CONSTRAINT [FK_PostionReq_Certification] FOREIGN KEY([CertificationID])
REFERENCES [dbo].[Certification] ([CertificationID])
GO
ALTER TABLE [dbo].[PositionReq] CHECK CONSTRAINT [FK_PostionReq_Certification]
GO
ALTER TABLE [dbo].[PositionReq] WITH CHECK ADD CONSTRAINT [FK_PostionReq_Postion] FOREIGN KEY([PositionID])
REFERENCES [dbo].[Position] ([PositionID])
GO
ALTER TABLE [dbo].[PositionReq] CHECK CONSTRAINT [FK_PostionReq_Postion]
GO
ALTER TABLE [dbo].[StaffEducation] WITH CHECK ADD CONSTRAINT [FK_StaffEducation_Education] FOREIGN KEY([EducationID])
REFERENCES [dbo].[Education] ([EducationID])
GO
ALTER TABLE [dbo].[StaffEducation] CHECK CONSTRAINT [FK_StaffEducation_Education]
GO
ALTER TABLE [dbo].[StaffEducation] WITH CHECK ADD CONSTRAINT [FK_StaffEducation_Staff] FOREIGN KEY([StaffMemberID])
REFERENCES [dbo].[StaffMember] ([StaffMemberID])
GO
ALTER TABLE [dbo].[StaffEducation] CHECK CONSTRAINT [FK_StaffEducation_Staff]
GO
ALTER TABLE [dbo].[StaffMember] WITH CHECK ADD CONSTRAINT [FK_StaffMember_Center] FOREIGN KEY([CenterID])
REFERENCES [dbo].[Center] ([CenterID])
GO
ALTER TABLE [dbo].[StaffMember] CHECK CONSTRAINT [FK_StaffMember_Center]
GO
ALTER TABLE [dbo].[StaffPosition] WITH CHECK ADD CONSTRAINT [FK_StaffPosition_Position] FOREIGN KEY([PositionID])
REFERENCES [dbo].[Position] ([PositionID])
GO
ALTER TABLE [dbo].[StaffPosition] CHECK CONSTRAINT [FK_StaffPosition_Position]
GO
ALTER TABLE [dbo].[StaffPosition] WITH CHECK ADD CONSTRAINT [FK_StaffPosition_StaffMember] FOREIGN KEY([StaffMemberID])
REFERENCES [dbo].[StaffMember] ([StaffMemberID])
GO
ALTER TABLE [dbo].[StaffPosition] CHECK CONSTRAINT [FK_StaffPosition_StaffMember]
GO
/****** Object: StoredProcedure [dbo].[AddNewCenter] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--Allows for the retrieval of one center an all its staffmemers by using @CenterId param or no param returns all centers and their respective staffmembers ordered by the centers Region, then name both ascending
CREATE Procedure [dbo].[AddNewCenter]
@StaffMemberID int,
@CenterName nvarchar(50) = NULL,
@CenterCounty nvarchar(50)= NULL,
@CenterRegion nvarchar(50)= NULL
as
begin
Declare @CenterID int
Select @CenterID = CenterID from Center where Name = @CenterName
If (@CenterID is null)
begin
Insert into Center(Name,County,Region) values(@CenterName,@CenterCounty,@CenterRegion)
Select @CenterID = SCOPE_IDENTITY()
end
update StaffMember set centerID=@CenterID where StaffMemberID=@StaffmemberID
end
GO
/****** Object: StoredProcedure [dbo].[AddNewEducation] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--Allows for the retrieval of one center an all its staffmemers by using @CenterId param or no param returns all centers and their respective staffmembers ordered by the centers Region, then name both ascending
CREATE Procedure [dbo].[AddNewEducation]
@StaffMemberID int,
@DegreeAbrv nvarchar(50)= NULL,
@DegreeLevel nvarchar(50)= NULL,
@DegreeType nvarchar(50)= NULL,
@DegreeDetail nvarchar(50)= NULL
as
begin
Declare @EducationID int
Select @EducationID = EducationID from Education where ((DegreeAbrv = @DegreeAbrv) and (DegreeType=@DegreeType))and (DegreeDetail=@DegreeDetail)
If (@EducationID is null)
begin
Insert into Education(DegreeAbrv, DegreeLevel,DegreeType,DegreeDetail) values(@DegreeAbrv, @DegreeLevel,@DegreeType,@DegreeDetail)
Select @EducationID = SCOPE_IDENTITY()
end
begin
insert into StaffEducation (StaffMemberID,EducationID) values (@StaffMemberID,@EducationID)
end
end
GO
/****** Object: StoredProcedure [dbo].[AddNewPosition] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--Inserts new position if position does not exist in table and then adds the positionid and staffmemberid into the junction table
CREATE Procedure [dbo].[AddNewPosition]
@StaffMemberID int,
@PositionTitle nvarchar(50)
as
begin
Declare @PositionID int
Select @PositionID = PositionID from Position where (PositionTitle = @PositionTitle)
If (@PositionID is null)
begin
Insert into Position (PositionTitle) values(@PositionTitle)
Select @PositionID = SCOPE_IDENTITY()
end
begin
if not exists(select positionId from staffposition where staffmemberID=@staffMemberID and positionID=@PositionID)
begin
insert into StaffPosition (StaffMemberID,PositionID) values (@StaffMemberID,@PositionID)
end
end
end
GO
/****** Object: StoredProcedure [dbo].[AddNewStaffMember] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--@Params as follows @FirstName,@LastName,@Email,@DateOfHire,
--@DirectorCredentials,@DCExpiration,@CDAInProgress,@CDAType,@CDAExpiration,@CDARenewalProcess,@Comments,@Goal,@MidYear,@EndYear,@GoalMet,@TAndAApp,@AppApp,
--@ClassCompleted,@ClassPaid,@RequiredHours,@HoursEarned,@Notes,@TermDate
--All nullable except @FirstName and @LastName
CREATE procedure [dbo].[AddNewStaffMember]
@StaffMemberID int,
@FirstName nvarchar(50),
@LastName nvarchar(50),
@Email nvarchar(50)= NULL,
@DateOfHire date= NULL,
@DirectorCredentials bit= NULL,
@DCExpiration date= NULL,
@CDAInProgress bit= False,
@CDAType nvarchar(50)= NULL,
@CDAExpiration date= NULL,
@CDARenewalProcess nvarchar(50)= NULL,
@Comments nvarchar(150)= NULL,
@Goal bit= NULL,
@MidYear bit= NULL,
@EndYear bit= NULL,
@GoalMet bit= False,
@TAndAApp bit= NULL,
@AppApp bit= NULL,
@ClassCompleted bit= NULL,
@ClassPaid bit= False,
@RequiredHours int= NULL,
@HoursEarned int= NULL,
@Notes nvarchar(200)= NULL,
@TermDate date= NULL,
@IsInactive bit =False
as
begin
Begin
Insert into StaffMember (FirstName,LastName,Email,DateOfHire,DirectorCredentials,DCExpiration,CDAInProgress,CDAType,CDAExpiration,CDARenewalProcess,Comments,Goal,MidYear,EndYear,GoalMet,TAndAApp,AppApp,ClassCompleted,ClassPaid,RequiredHours,HoursEarned,Notes,
TermDate,IsInactive) output inserted.staffMemberID values(@FirstName,@LastName,@Email,@DateOfHire,@DirectorCredentials,@DCExpiration,@CDAInProgress,@CDAType,@CDAExpiration,@CDARenewalProcess,@Comments,@Goal,@MidYear,@EndYear,@GoalMet,@TAndAApp,@AppApp,@ClassCompleted,@ClassPaid,@RequiredHours,@HoursEarned,@Notes,@TermDate,@IsInactive)
Select @StaffMemberID = SCOPE_IDENTITY()
End
End
GO
/****** Object: StoredProcedure [dbo].[AddNewUser] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- Takes variables @Email,@FirstName,@LastName,@AccessLevel,@PasswordHash to creates a system user to administer and view staff members
CREATE procedure [dbo].[AddNewUser]
@UserID int =null,
@Email varchar (150),
@FirstName varchar(50)=null,
@LastName varchar(50)=null,
@AccessLevel int,
@Passwordhash varchar(128)
as
Begin
Insert into ECSUser (Email,FirstName,LastName,AccessLevel,PasswordHash) output inserted.UserID values(@Email,@FirstName,@LastName,@AccessLevel,@PasswordHash)
Select @UserID = SCOPE_IDENTITY()
End
GO
/****** Object: StoredProcedure [dbo].[AnnualReset] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE Procedure [dbo].[AnnualReset]
as
begin
update StaffMember Set goal =0, MidYear=0, EndYear=0, GoalMet=0, HoursEarned=0
end
GO
/****** Object: StoredProcedure [dbo].[AuthenticateUser] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE Procedure [dbo].[AuthenticateUser]
@Email varchar(150),
@PasswordHash varchar(128)
as
begin
Select * FROM ECSUser
where Email=@Email and PasswordHash = @PasswordHash
end
GO
/****** Object: StoredProcedure [dbo].[deleteStaffMember] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--Deletes the staff members education from the junction table and then deletes the staff member
CREATE Procedure [dbo].[deleteStaffMember]
@staffMemberID int
as
begin
begin
delete from StaffEducation where staffMemberID=@staffMemberID
end
begin
delete from StaffPosition where staffMemberID=@staffMemberID
end
begin
delete from CertCompletion where StaffMemberID=@staffMemberID
end
begin
delete from StaffMember where StaffMemberID=@staffMemberID
end
end
GO
/****** Object: StoredProcedure [dbo].[deleteUser] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--deletes the user from the database
CREATE Procedure [dbo].[deleteUser]
@UserID int
as
if (@UserID != 3)
begin
delete from ECSUser where UserID=@UserID
end
GO
/****** Object: StoredProcedure [dbo].[GetCenter] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--Allows for the retrieval of one center an all its staffmemers by using @CenterId param or no param returns all centers and their respective staffmembers ordered by the centers Region, then name both ascending
CREATE Procedure [dbo].[GetCenter]
@CenterID int = NULL
as
begin
Select c.CenterID,c.Name,c.County,c.Region,sm.StaffMemberID,sm.FirstName,sm.LastName,sm.Email,sm.DateofHire, sm.DirectorCredentials,sm.DCExpiration,sm.CDAInProgress,sm.CDAType,sm.CDARenewalProcess,sm.Comments,sm.Goal,sm.MidYear,
sm.EndYear,sm.GoalMet,sm.TAndAApp,sm.AppApp,sm.ClassCompleted,sm.ClassPaid,sm.RequiredHours,sm.HoursEarned,sm.Notes,sm.TermDate, p.PositionID, p.PositionTitle
FROM Center as c
Left OUTER JOIN StaffMember as sm on c.CenterID=sm.CenterID
Left OUTER JOIN StaffPosition as sp on sp.StaffMemberID=sm.StaffMemberID
Left OUTER JOIN Position as p on p.PositionID=sp.PositionID
where sm.CenterID=@CenterID OR ISNULL(@CenterID, '') = ''
order by Region asc , Name asc
end
GO
/****** Object: StoredProcedure [dbo].[GetDashBoardLists] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE Procedure [dbo].[GetDashBoardLists]
@StaffMemberID int =NULL
as
begin
SELECT StaffMemberID,FirstName,LastName,Email,DateOfHire,Goal,MidYear,EndYear,GoalMet,TAndAApp,ClassCompleted,ClassPaid,RequiredHours,HoursEarned,TermDate,IsInactive,AppApp,
JSON_QUERY((SELECT c.CenterID,c.Name, c.County,c.Region
FROM Center as c
WHERE sm.CenterID = c.CenterID
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER)) AS Center,
JSON_QUERY((SELECT e.EducationID, e.DegreeAbrv, e.DegreeLevel,e.DegreeType, e.DegreeDetail
FROM Education as e
INNER JOIN StaffEducation as se on se.EducationID = e.EducationID
WHERE sm.StaffMemberID = se.StaffMemberID
FOR JSON PATH)) AS Education,
JSON_QUERY((SELECT p.PositionID, p.PositionTitle,(SELECT c.CertificationID, c.CertName, c.CertExpireAmount,cc.CertCompletionDate, cc.CertInProgress
from Certification as c
inner join PositionReq as pr on pr.CertificationID =c.CertificationID and p.PositionID =pr.PositionID
left JOIN CERTCompletion as cc on cc.CertificationID=c.CertificationID and cc.StaffMemberID =sm.StaffMemberID FOR JSON PATH ) as requiredCerts
FROM Position as p
left JOIN StaffPosition as sp on sp.PositionID = p.PositionID
WHERE sm.StaffMemberID = sp.StaffMemberID
FOR JSON PATH )) as Position,
JSON_QUERY((SELECT c.CertificationID as 'Cert.CertificationID', c.CertName as 'Cert.CertName', c.CertExpireAmount as 'Cert.CertExpireAmount', cc.CertCompletionDate as 'DateCompleted', cc.CertInProgress
FROM Certification as c
inner join CertCompletion as cc on c.CertificationID = cc.CertificationID and sm.StaffMemberID = cc.StaffMemberID
WHERE sm.StaffMemberID = cc.StaffMemberID and c.CertificationID = cc.CertificationID
FOR JSON PATH)) as Cert
FROM StaffMember as sm
where sm.StaffMemberID=@StaffMemberID OR ISNULL(@StaffMemberID, '') = ''
end
GO
/****** Object: StoredProcedure [dbo].[GetEmptyCenters] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE Procedure [dbo].[GetEmptyCenters]
as
begin
select c.CenterID, c.Name, c.County, C.Region from Center as c
left join StaffMember as sm on sm.CenterID=c.CenterID
where StaffMemberID is Null
end
GO
/****** Object: StoredProcedure [dbo].[GetEmptyEducations] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE Procedure [dbo].[GetEmptyEducations]
as
begin
select e.EducationID, e.DegreeAbrv, e.DegreeLevel, e.DegreeType, e.DegreeDetail from StaffEducation as se
right join Education as e on se.EducationID=e.EducationID
where StaffMemberID is Null
end
GO
/****** Object: StoredProcedure [dbo].[GetEmptyPositions] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE Procedure [dbo].[GetEmptyPositions]
as
begin
select p.PositionID, p.PositionTitle from Position as p
left join StaffPosition as sp on p.PositionID =sp.PositionID
left join PositionReq as pr on p.PositionID =pr.PositionID
where StaffMemberID is null and CertificationID is null
end
GO
/****** Object: StoredProcedure [dbo].[GetSelectLists] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE Procedure [dbo].[GetSelectLists]
as
begin
select c.Name as CenterName, c.County as CenterCounty, c.Region as CenterRegion,e.DegreeAbrv as EducationAbrv, e.DegreeLevel as EducationLevel, e.DegreeType as EducationType, e.DegreeDetail as EducationDetail, p.PositionTitle as Position, cert.CertName as CertCompleted
from Center as c
full outer join Education as e on c.CenterID=e.EducationID
full outer join Position as p on c.CenterID=p.PositionID
full outer join Certification as cert on c.CenterID=cert.CertificationID
end
GO
/****** Object: StoredProcedure [dbo].[GetStaffMember] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--@params are @StaffMemberID
--Allows the user to get a list of StaffMembers with their associated education and centers, use the @StaffMemberID to retrieve just one StaffMember
CREATE Procedure [dbo].[GetStaffMember]
@StaffMemberID int =NULL
as
begin
Select sm.StaffMemberID, sm.FirstName, sm.LastName, sm.Email,sm.DateofHire,sm.DirectorCredentials, sm.DCExpiration, sm.CDAInProgress, sm.CDAType,
sm.CDAExpiration,sm.CDARenewalProcess,sm.Comments,sm.Goal,sm.MidYear,sm.EndYear,sm.GoalMet,sm.TAndAApp,sm.AppApp,sm.ClassCompleted,sm.ClassPaid,
sm.RequiredHours,sm.HoursEarned,sm.Notes, sm.TermDate,sm.IsInactive,p.PositionID,p.PositionTitle, c.CenterID,c.Name,c.County,c.Region, e.EducationID,e.DegreeAbrv,
e.DegreeLevel, e.DegreeType, e.DegreeDetail, cc.CertInProgress, cc.CertCompletionDate as DateCompleted, cert.CertificationID, cert.CertName, cert.CertExpireAmount
FROM StaffMember as sm
left Outer JOIN StaffPosition as sp on sp.StaffMemberID=sm.StaffMemberID
left Outer JOIN Position as p on p.PositionID=sp.PositionID
Left Outer JOIN Center as c on c.CenterID=sm.CenterID
Left Outer JOIN StaffEducation as se on se.StaffMemberID=sm.StaffMemberID
Left Outer JOIN Education as e on e.educationID=se.EducationID
Left Outer JOIN CertCompletion as cc on cc.StaffMemberID=sm.StaffMemberID
Left Outer JOIN Certification as cert on cert.CertificationID=cc.CertificationID
where sm.StaffMemberID=@StaffMemberID OR ISNULL(@StaffMemberID, '') = ''
order by LastName asc
end
GO
/****** Object: StoredProcedure [dbo].[RemovePosition] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--Takes the input of staffMemberID and the positionID you want to remove from that staff members and deletes it from the junction table to Disassociate
CREATE Procedure [dbo].[RemovePosition]
@staffMemberID int,
@positionID int
as
begin
delete from StaffPosition where staffMemberID=@staffMemberID and positionID=@positionID
end
GO
/****** Object: StoredProcedure [dbo].[RemoveStaffEducation] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--Takes the input of staffMemberID and the educationID you want to remove from that staff members and deletes it from the junction table to dissacciate
CREATE Procedure [dbo].[RemoveStaffEducation]
@staffMemberID int,
@educationID int
as
begin
delete from StaffEducation where staffMemberID=@staffMemberID and educationID=@educationID
end
GO
/****** Object: StoredProcedure [dbo].[SeedDatabase] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--Seeds Database with initial information
CREATE Procedure [dbo].[SeedDatabase]
as
begin
-------------------------------- DCF Certs ---------------------------------------------
If Not Exists (Select CertName from Certification where CertName like '%DCF Training 30 Day%')
BEGIN
Insert INTO Certification (CertName,CertExpireAmount) values('DCF Training 30 Day','1')
END
If Not Exists (Select CertName from Certification where CertName like '%DCF Training 60 Day%')
BEGIN
Insert INTO Certification (CertName,CertExpireAmount) values('DCF Training 60 Day','2')
END
If Not Exists (Select CertName from Certification where CertName like '%DCF Training 90 Day%')
BEGIN
Insert INTO Certification (CertName,CertExpireAmount) values('DCF Training 90 Day','3')
END
If Not Exists (Select CertName from Certification where CertName like '%DCF Director Credential%')
BEGIN
Insert INTO Certification (CertName,CertExpireAmount) values('DCF Director Credential','36')
END
If Not Exists (Select CertName from Certification where CertName like '%DCF Staff Credential%')
BEGIN
Insert INTO Certification (CertName,CertExpireAmount) values('DCF Staff Credential','36')
END
----------------------------------- CDA Certs-------------------------------------------
If Not Exists (Select CertName from Certification where CertName like '%CDA PreSchool%')
BEGIN
Insert INTO Certification (CertName,CertExpireAmount) values('CDA PreSchool','36')
END
If Not Exists (Select CertName from Certification where CertName like '%CDA Infant Toddler%')
BEGIN
Insert INTO Certification (CertName,CertExpireAmount) values('CDA Infant Toddler','36')
END
If Not Exists (Select CertName from Certification where CertName like '%Family Child Care%')
BEGIN
Insert INTO Certification (CertName,CertExpireAmount) values('Family Child Care','36')
END
If Not Exists (Select CertName from Certification where CertName like '%Home Visitor%')
BEGIN
Insert INTO Certification (CertName,CertExpireAmount) values('Home Visitor','36')
END
----------------------------------- Class Certs -----------------------------------------
If Not Exists (Select CertName from Certification where CertName like '%Class Pre-K%')
BEGIN
Insert INTO Certification (CertName,CertExpireAmount) values('Class Pre-K','12')
END
If Not Exists (Select CertName from Certification where CertName like '%Class Infant Toddler%')
BEGIN
Insert INTO Certification (CertName,CertExpireAmount) values('Class Infant Toddler','12')
END
If Not Exists (Select CertName from Certification where CertName like '%Class Toddler%')
BEGIN
Insert INTO Certification (CertName,CertExpireAmount) values('Class Toddler','12')
END
--------------------------------- Add Positions ----------------------------------------
If Not Exists (Select PositionTitle from Position where PositionTitle like '%Lead Teacher%')
BEGIN
Insert INTO Position (PositionTitle) values('Lead Teacher')
END
If Not Exists (Select PositionTitle from Position where PositionTitle like '%Center Manager%')
BEGIN
Insert INTO Position (PositionTitle) values('Center Manager')
END
end
GO
/****** Object: StoredProcedure [dbo].[SetSeedAccount] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--Seeds the root account if it does not exist and if it does resets password to default
CREATE Procedure [dbo].[SetSeedAccount]
as
begin
If Not Exists (Select Email from ECSUser where Email like '%SeedAdmin@ecs4kids.org%')
BEGIN
Insert INTO ECSUser (Email,FirstName,LastName, AccessLevel, PasswordHash) values('SeedAdmin@ecs4kids.org','Seed','Admin',0,'$2b$10$K9i6CZOX4VBFdwASq8CZv.exP8PNa6HVDDMkvQr/zas1Lh2coztoi')
END
else
BEGIN
update ECSUser set Email= 'SeedAdmin@ecs4kids.org', FirstName= 'Seed', LastName ='Admin',AccessLevel=0,
PasswordHash='$2b$10$K9i6CZOX4VBFdwASq8CZv.exP8PNa6HVDDMkvQr/zas1Lh2coztoi' where Email like '%SeedAdmin@ecs4kids.org%'
END
End
GO
/****** Object: StoredProcedure [dbo].[sp_alterdiagram] Script Date: 4/18/2018 9:16:24 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[sp_alterdiagram]
(
@diagramname sysname,
@owner_id int = null,
@version int,
@definition varbinary(max)
)
WITH EXECUTE AS 'dbo'
AS
BEGIN
set nocount on
declare @theId int
declare @retval int
declare @IsDbo int
declare @UIDFound int
declare @DiagId int
declare @ShouldChangeUID int
if(@diagramname is null)
begin
RAISERROR ('Invalid ARG', 16, 1)
return -1
end
execute as caller;
select @theId = DATABASE_PRINCIPAL_ID();
select @IsDbo = IS_MEMBER(N'db_owner');
if(@owner_id is null)
select @owner_id = @theId;
revert;
select @ShouldChangeUID = 0
select @DiagId = diagram_id, @UIDFound = principal_id from dbo.sysdiagrams where principal_id = @owner_id and name = @diagramname
if(@DiagId IS NULL or (@IsDbo = 0 and @theId <> @UIDFound))
begin
RAISERROR ('Diagram does not exist or you do not have permission.', 16, 1);
return -3
end
if(@IsDbo <> 0)
begin
if(@UIDFound is null or USER_NAME(@UIDFound) is null) -- invalid principal_id
begin
select @ShouldChangeUID = 1 ;
end
end
-- update dds data
update dbo.sysdiagrams set definition = @definition where diagram_id = @DiagId ;
-- change owner
if(@ShouldChangeUID = 1)
update dbo.sysdiagrams set principal_id = @theId where diagram_id = @DiagId ;