-
Notifications
You must be signed in to change notification settings - Fork 0
/
kod generujący.sql
2804 lines (2751 loc) · 213 KB
/
kod generujący.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
USE [master]
GO
/****** Object: Database [dlugosz_a] Script Date: 22/01/2019 15:56:04 ******/
CREATE DATABASE [dlugosz_a]
CONTAINMENT = NONE
ON PRIMARY
( NAME = N'dlugosz_a', FILENAME = N'/var/opt/mssql/data/dlugosz_a.mdf' , SIZE = 16384KB , MAXSIZE = 30720KB , FILEGROWTH = 2048KB )
LOG ON
( NAME = N'dlugosz_a_log', FILENAME = N'/var/opt/mssql/data/dlugosz_a.ldf' , SIZE = 30720KB , MAXSIZE = 30720KB , FILEGROWTH = 2048KB )
GO
ALTER DATABASE [dlugosz_a] SET COMPATIBILITY_LEVEL = 140
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [dlugosz_a].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [dlugosz_a] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [dlugosz_a] SET ANSI_NULLS OFF
GO
ALTER DATABASE [dlugosz_a] SET ANSI_PADDING OFF
GO
ALTER DATABASE [dlugosz_a] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [dlugosz_a] SET ARITHABORT OFF
GO
ALTER DATABASE [dlugosz_a] SET AUTO_CLOSE OFF
GO
ALTER DATABASE [dlugosz_a] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [dlugosz_a] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [dlugosz_a] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [dlugosz_a] SET CURSOR_DEFAULT GLOBAL
GO
ALTER DATABASE [dlugosz_a] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [dlugosz_a] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [dlugosz_a] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [dlugosz_a] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [dlugosz_a] SET ENABLE_BROKER
GO
ALTER DATABASE [dlugosz_a] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [dlugosz_a] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [dlugosz_a] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [dlugosz_a] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [dlugosz_a] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [dlugosz_a] SET READ_COMMITTED_SNAPSHOT OFF
GO
ALTER DATABASE [dlugosz_a] SET HONOR_BROKER_PRIORITY OFF
GO
ALTER DATABASE [dlugosz_a] SET RECOVERY FULL
GO
ALTER DATABASE [dlugosz_a] SET MULTI_USER
GO
ALTER DATABASE [dlugosz_a] SET PAGE_VERIFY CHECKSUM
GO
ALTER DATABASE [dlugosz_a] SET DB_CHAINING OFF
GO
ALTER DATABASE [dlugosz_a] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )
GO
ALTER DATABASE [dlugosz_a] SET TARGET_RECOVERY_TIME = 60 SECONDS
GO
ALTER DATABASE [dlugosz_a] SET DELAYED_DURABILITY = DISABLED
GO
EXEC sys.sp_db_vardecimal_storage_format N'dlugosz_a', N'ON'
GO
ALTER DATABASE [dlugosz_a] SET QUERY_STORE = OFF
GO
USE [dlugosz_a]
GO
/****** Object: UserDefinedFunction [dbo].[CalculatePriceForReservation] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE function [dbo].[CalculatePriceForReservation] (@Email varchar(100), @DateOrdered date)
returns money
as
begin
declare @ReservationID int;
declare @CustomerID int
EXEC @CustomerID = dbo.FindCustomerByEmail @Email -- varchar(15)
select @ReservationID = max(ReservationID)
from ConferenceReservations
where CustomerID = @CustomerID AND DateOrdered = @DateOrdered
return (select sum(AdultPrice*ReservedAdultSeats + StudentPrice*ReservedStudentSeats)
from dbo.ReservationPrices(@DateOrdered, @ReservationID) r
join ConferenceDayReservation cdr
on cdr.ReservationID = @ReservationID and cdr.ConferenceDayID in (select ConferenceDayID
from ConferenceDays cd
where cd.ConferenceID = r.ConferenceID))
end
GO
/****** Object: UserDefinedFunction [dbo].[ConferenceDayReservationSize] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[ConferenceDayReservationSize](@ConferenceDayReservationID int)
RETURNS INT
AS
BEGIN
DECLARE @Size INT = (SELECT SUM(c.ReservedAdultSeats )+ SUM(c.ReservedAdultSeats)
FROM dbo.ConferenceDayReservation c
WHERE c.DayReservationID = @ConferenceDayReservationID)
RETURN @Size
END
GO
/****** Object: UserDefinedFunction [dbo].[ConferenceOrderedAfterCreated] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[ConferenceOrderedAfterCreated] (@ConferenceDayID INT, @ReservationID INT)
RETURNS INT
BEGIN
DECLARE @ConfCreated DATE = (SELECT Conferences.CreatedOn FROM dbo.ConferenceDays
INNER JOIN Conferences ON Conferences.ConferenceID = ConferenceDays.ConferenceID
WHERE ConferenceDays.ConferenceDayID = @ConferenceDayID)
DECLARE @OrderDate DATE = (SELECT DateOrdered FROM dbo.ConferenceReservations
WHERE ReservationID = @ReservationID)
RETURN DATEDIFF(DAY, @ConfCreated, @OrderDate)
END
GO
/****** Object: UserDefinedFunction [dbo].[ConferenceSize] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[ConferenceSize](@ConferenceDayID INT)
RETURNS int
BEGIN
DECLARE @size int = (SELECT ParticipantsLimit FROM ConferenceDays
INNER JOIN conferences ON Conferences.ConferenceID = ConferenceDays.ConferenceID
WHERE ConferenceDayID = @ConferenceDayID)
RETURN @size
END
GO
/****** Object: UserDefinedFunction [dbo].[DayReservationTotalSeats] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[DayReservationTotalSeats](@ConferenceDayReservationID INT)
RETURNS INT
BEGIN
DECLARE @result INT
SELECT @result = SUM(ReservedAdultSeats) + SUM(ReservedStudentSeats)
FROM dbo.ConferenceDayReservation cdr
WHERE cdr.DayReservationID = @ConferenceDayReservationID
RETURN @result
end
GO
/****** Object: UserDefinedFunction [dbo].[DiscountForConference] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE function [dbo].[DiscountForConference](@DateOrdered date, @ConferenceID int)
returns real
as
begin
declare @TimeDiscount real;
if not exists (select DiscountRate
from ConferencePricetables cp
where cp.ConferenceID = @ConferenceID and @DateOrdered between cp.PriceStartsOn and cp.PriceEndsOn)
set @TimeDiscount = 0
else
set @TimeDiscount = (select DiscountRate
from ConferencePricetables cp
where cp.ConferenceID = @ConferenceID and @DateOrdered between cp.PriceStartsOn and cp.PriceEndsOn)
return @TimeDiscount
end
GO
/****** Object: UserDefinedFunction [dbo].[EmptySeatsInWorkshopReservation] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[EmptySeatsInWorkshopReservation] (@DayParticipantID INT, @ConferenceDayWorkshopID int)
RETURNS INT
BEGIN
DECLARE @SeatsReserved INT, @SeatsOccupied INT, @DayReservationID INT
SELECT @DayReservationID = ConferenceDayReservationID
FROM dbo.ConferenceDayParticipants
WHERE ConferenceDayParticipantID = @DayParticipantID
SELECT @SeatsReserved = ReservedSeats
FROM dbo.WorkshopReservation
WHERE ConferenceDayReservationID = @DayReservationID AND ConferenceDayWorkshopID = @ConferenceDayWorkshopID
SELECT @SeatsOccupied = COUNT(*)
FROM dbo.WorkshopParticipants
INNER JOIN dbo.ConferenceDayParticipants ON ConferenceDayParticipants.ConferenceDayParticipantID = WorkshopParticipants.ConferenceDayParticipantID
WHERE ConferenceDayWorkshopID = @ConferenceDayWorkshopID AND ConferenceDayReservationID = @DayReservationID
IF @SeatsReserved IS NULL RETURN -1
RETURN @SeatsReserved - @SeatsOccupied
END
GO
/****** Object: UserDefinedFunction [dbo].[FindCompanyByEmail] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE function [dbo].[FindCompanyByEmail] (@Email varchar(100))
returns int
as
begin
return (select CompanyID from Companies where Email = @Email)
end
GO
/****** Object: UserDefinedFunction [dbo].[FindCompanyByName] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create function [dbo].[FindCompanyByName] (@Name varchar(150))
returns int
as
begin
return (select CompanyID from Companies where CompanyName = @Name)
end
GO
/****** Object: UserDefinedFunction [dbo].[FindCompanyByNIP] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create function [dbo].[FindCompanyByNIP] (@NIP char(10))
returns int
as
begin
return (select CompanyID from Companies where NIP = @NIP)
end
GO
/****** Object: UserDefinedFunction [dbo].[FindCompanyByPhone] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create function [dbo].[FindCompanyByPhone] (@Phone varchar(15))
returns int
as
begin
return (select CompanyID from Companies where Phone = @Phone)
end
GO
/****** Object: UserDefinedFunction [dbo].[FindCustomerByEmail] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE function [dbo].[FindCustomerByEmail] (@Email varchar(100))
returns int
as
begin
declare @CompanyID int;
exec @CompanyID = FindCompanyByEmail @Email;
if @CompanyID is null
begin
declare @ParticipantID int;
EXEC @ParticipantID = FindParticipantByEmail @Email;
return (select CustomerID from PrivateCustomers where ParticipantID = @ParticipantID)
end
return @CompanyID
end
GO
/****** Object: UserDefinedFunction [dbo].[FindParticipantByEmail] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE function [dbo].[FindParticipantByEmail] (@Email varchar(100))
returns int
as
begin
return (select ParticipantID from Participants where Email = @Email)
end
GO
/****** Object: UserDefinedFunction [dbo].[FindParticipantByName] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create function [dbo].[FindParticipantByName] (@FirstName varchar(30), @LastName varchar(50))
returns int
as
begin
return (select ParticipantID from Participants where FirstName = @FirstName and LastName = @LastName)
end
GO
/****** Object: UserDefinedFunction [dbo].[FindWorkshop] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE function [dbo].[FindWorkshop] (@Name VARCHAR(200))
RETURNS INT
BEGIN
DECLARE @ID INT = (SELECT WorkshopID FROM dbo.Workshops WHERE Name = @Name)
RETURN @ID
END
GO
/****** Object: UserDefinedFunction [dbo].[GetConferenceStartDate] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create function [dbo].[GetConferenceStartDate](@ConferenceID int)
returns date
as
begin
return (select StartDate from Conferences where ConferenceID = @ConferenceID)
end
GO
/****** Object: UserDefinedFunction [dbo].[GetLatestDiscount] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE function [dbo].[GetLatestDiscount](@ConferenceID int)
returns real
as
begin
declare @discount real;
if exists (select *
from ConferencePricetables
where ConferenceID = @ConferenceID)
set @discount = (select min(DiscountRate)
from ConferencePricetables
where ConferenceID = @ConferenceID)
else
set @discount = 1
return @discount
end
GO
/****** Object: UserDefinedFunction [dbo].[GetNumberOfPaidReservationForCustomer] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE function [dbo].[GetNumberOfPaidReservationForCustomer](@Email varchar(100))
returns int
begin
declare @CustomerID int;
exec @CustomerID = dbo.FindCustomerByEmail @Email;
return (select count(*)
from ConferenceReservations
where CustomerID = @CustomerID and DatePaid is not null)
end
GO
/****** Object: UserDefinedFunction [dbo].[HasParticipantCollidingWorkshops] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[HasParticipantCollidingWorkshops](@NewWorkshopID INT, @ConferenceDayParticipantID int)
RETURNS BIT
BEGIN
DECLARE @Times TABLE (
TimeID INT PRIMARY KEY IDENTITY(0,1),
StartTime TIME,
EndTime time
)
INSERT INTO @Times
SELECT StartTime, EndTime
FROM dbo.WorkshopParticipants
INNER JOIN dbo.ConferenceDayWorkshops ON ConferenceDayWorkshops.ConferenceDayWorkshopID = WorkshopParticipants.ConferenceDayWorkshopID
WHERE ConferenceDayID = (SELECT ConferenceDayID
FROM dbo.ConferenceDayWorkshops
WHERE ConferenceDayWorkshopID = @NewWorkshopID)
AND ConferenceDayParticipantID = @ConferenceDayParticipantID;
DECLARE @has BIT = (SELECT COUNT(*) from
(SELECT a.TimeID
FROM @Times AS a
INNER JOIN @Times AS b ON ((a.StartTime BETWEEN b.StartTime AND b.EndTime) OR
(a.EndTime BETWEEN b.StartTime AND b.EndTime) OR
(a.StartTime < b.StartTime AND a.EndTime > b.EndTime))
AND (a.TimeID != b.TimeID)) AS t)
RETURN @has
END
GO
/****** Object: UserDefinedFunction [dbo].[IsReservationByCompany] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create function [dbo].[IsReservationByCompany] (@ReservationID int)
returns bit
as
begin
declare @CompanyID int
select @CompanyID = Companies.CompanyID
from ConferenceReservations
inner join Customers on ConferenceReservations.CustomerID = Customers.CustomerID
left join Companies on customers.CustomerID = CompanyID
where ReservationID = @ReservationID
if @CompanyID is not null begin return 1 end
return 0
end
GO
/****** Object: UserDefinedFunction [dbo].[IsReservationPaid] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[IsReservationPaid](@ReservationID INT)
RETURNS BIT
begin
RETURN (SELECT COUNT(*) FROM
(SELECT DatePaid
FROM ConferenceReservations
WHERE DatePaid IS NOT NULL AND ReservationID = @ReservationID) t)
END
GO
/****** Object: UserDefinedFunction [dbo].[NewPriceAtTheDayAfterPrevious] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[NewPriceAtTheDayAfterPrevious](@ConferenceID INT)
RETURNS int
BEGIN
IF (SELECT COUNT(*) FROM dbo.ConferencePricetables) = 1 RETURN 1
DECLARE @Dates TABLE (
DateID INT PRIMARY KEY IDENTITY(1,1),
StartDate date,
EndDate date
)
INSERT INTO @Dates (StartDate, EndDate)
SELECT TOP 2 PriceStartsOn, PriceEndsOn
FROM dbo.ConferencePricetables
WHERE ConferenceID = @ConferenceID
ORDER BY PriceStartsOn DESC
DECLARE @PrevStepEnd DATE = (SELECT EndDate FROM @Dates WHERE DateID = 2)
DECLARE @NewStepStart DATE = (SELECT StartDate FROM @Dates WHERE DateID = 1)
RETURN DATEDIFF(DAY, @PrevStepEnd, @NewStepStart)
END
GO
/****** Object: UserDefinedFunction [dbo].[OrganisedLaterThanHired] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[OrganisedLaterThanHired] (@EmployeeID int, @ConferenceID int)
RETURNS int
BEGIN
DECLARE @HireDate DATE = (SELECT HireDate FROM dbo.OurEmployees WHERE EmployeeID = @EmployeeID)
DECLARE @ConfDate DATE = (SELECT StartDate FROM Conferences WHERE ConferenceID = @ConferenceID)
RETURN DATEDIFF(DAY, @HireDate, @ConfDate)
END
GO
/****** Object: UserDefinedFunction [dbo].[ReservationEarlierThanConferenceDay] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[ReservationEarlierThanConferenceDay](@ConferenceDayID int, @ReservationID INT)
RETURNS INT
BEGIN
DECLARE @ConfDate DATE = (SELECT Date FROM dbo.ConferenceDays WHERE ConferenceDayID = @ConferenceDayID)
DECLARE @Orderdate DATE = (SELECT DateOrdered FROM dbo.ConferenceReservations WHERE ReservationID = @ReservationID)
RETURN DATEDIFF(DAY, @Orderdate, @ConfDate)
END
GO
/****** Object: UserDefinedFunction [dbo].[ReservedSeatsForWorkshop] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[ReservedSeatsForWorkshop](@ConferenceDayWorkshopID int)
RETURNS int
BEGIN
DECLARE @Sum INT = (SELECT SUM(ReservedSeats)
FROM WorkshopReservation
WHERE ConferenceDayWorkshopID = @ConferenceDayWorkshopID)
RETURN @Sum
end
GO
/****** Object: UserDefinedFunction [dbo].[ReservedSeatsPerConferenceDay] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[ReservedSeatsPerConferenceDay](@ConferenceDayID INT)
RETURNS INT
BEGIN
DECLARE @number INT = (SELECT SUM(ReservedAdultSeats) + SUM(ReservedStudentSeats)
FROM dbo.ConferenceDayReservation
WHERE ConferenceDayID = @ConferenceDayID)
IF @number IS NULL BEGIN SET @number = 0 end
RETURN @number
END
GO
/****** Object: UserDefinedFunction [dbo].[ViewOrdersByEmailAsCustomer] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[ViewOrdersByEmailAsCustomer] (@CustomerEmail VARCHAR(100))
RETURNS @Data TABLE (
DateOrdered DATE,
DatePaid DATE,
TotalAmount MONEY
)
BEGIN
INSERT INTO @Data (DateOrdered, DatePaid, TotalAmount)
SELECT DateOrdered, DatePaid, dbo.CalculatePriceForReservation(@CustomerEmail, DateOrdered)
FROM dbo.ConferenceReservations
INNER JOIN dbo.CustomerContactData ON CustomerContactData.CustomerID = ConferenceReservations.CustomerID
WHERE Email = @CustomerEmail
RETURN
END
GO
/****** Object: UserDefinedFunction [dbo].[WorkshopReservationOnDayReservationConference] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[WorkshopReservationOnDayReservationConference] (@DayReservationID INT, @WorkshopInDayID INT)
RETURNS INT
BEGIN
DECLARE @ConferenceDayAtReservation INT = (SELECT ConferenceDayID FROM dbo.ConferenceDayReservation WHERE DayReservationID = @DayReservationID)
DECLARE @ConferenceDayAtWorkshop INT = (SELECT ConferenceDayID FROM dbo.ConferenceDayWorkshops WHERE ConferenceDayWorkshopID = @WorkshopInDayID)
RETURN @ConferenceDayAtReservation - @ConferenceDayAtWorkshop
END
GO
/****** Object: UserDefinedFunction [dbo].[WorkshopSeatsLimit] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[WorkshopSeatsLimit](@WorkshopID INT)
RETURNS INT
AS
BEGIN
DECLARE @Limit INT = (SELECT ParticipantsLimit
FROM dbo.ConferenceDayWorkshops
WHERE ConferenceDayWorkshopID = @WorkshopID)
RETURN @Limit
end
GO
/****** Object: Table [dbo].[PrivateCustomers] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PrivateCustomers](
[CustomerID] [int] NOT NULL,
[ParticipantID] [int] NOT NULL,
PRIMARY KEY CLUSTERED
(
[CustomerID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [UniqueParticipant] UNIQUE NONCLUSTERED
(
[ParticipantID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Customers] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Customers](
[CustomerID] [int] IDENTITY(0,1) NOT NULL,
[Street] [nvarchar](74) NULL,
[HouseNumber] [nvarchar](5) NULL,
[AppartmentNumber] [int] NULL,
[CityID] [int] NULL,
[PostalCode] [char](6) NULL,
PRIMARY KEY CLUSTERED
(
[CustomerID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Companies] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Companies](
[CompanyID] [int] NOT NULL,
[CompanyName] [nvarchar](150) NULL,
[NIP] [char](10) NOT NULL,
[Phone] [varchar](15) NOT NULL,
[Email] [varchar](100) NULL,
CONSTRAINT [PK__Companie__2D971C4C89B49313] PRIMARY KEY CLUSTERED
(
[CompanyID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [UQ__Companie__5C7E359E2281BCA6] UNIQUE NONCLUSTERED
(
[Phone] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [UQ__Companie__C7DEC3C65B7646BC] UNIQUE NONCLUSTERED
(
[NIP] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [UQ_EMAIL] UNIQUE NONCLUSTERED
(
[Email] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Participants] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Participants](
[ParticipantID] [int] IDENTITY(0,1) NOT NULL,
[FirstName] [varchar](30) NULL,
[LastName] [varchar](50) NULL,
[Phone] [varchar](15) NULL,
[Email] [varchar](100) NULL,
CONSTRAINT [PK__Particip__7227997EFB4A4EAE] PRIMARY KEY CLUSTERED
(
[ParticipantID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[ConferenceReservations] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ConferenceReservations](
[ReservationID] [int] IDENTITY(0,1) NOT NULL,
[CustomerID] [int] NOT NULL,
[DateOrdered] [date] NOT NULL,
[DatePaid] [date] NULL,
PRIMARY KEY CLUSTERED
(
[ReservationID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [UQ_ONE_DAY_ONE_CUSTOMER_ONE_ORDER] UNIQUE NONCLUSTERED
(
[CustomerID] ASC,
[DateOrdered] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: View [dbo].[Payments] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[Payments] AS
SELECT ReservationID, CompanyName, Email, DateOrdered, DatePaid,
dbo.CalculatePriceForReservation( Companies.Email, DateOrdered) AS Price
FROM ConferenceReservations
JOIN Customers
ON ConferenceReservations.CustomerID = Customers.CustomerID
JOIN Companies
ON Customers.CustomerID = Companies.CompanyID
UNION
SELECT ReservationID, (FirstName + ' ' + LastName), Email, DateOrdered, DatePaid,
dbo.CalculatePriceForReservation( Participants.Email, DateOrdered) AS Price
FROM ConferenceReservations
JOIN Customers
ON ConferenceReservations.CustomerID = Customers.CustomerID
JOIN PrivateCustomers
ON Customers.CustomerID = PrivateCustomers.CustomerID
JOIN Participants
ON PrivateCustomers.ParticipantID = Participants.ParticipantID
GO
/****** Object: View [dbo].[UnpaidReservations] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create view [dbo].[UnpaidReservations]
as
select ReservationID, CompanyName, DateOrdered
from ConferenceReservations
join Customers
on ConferenceReservations.CustomerID = Customers.CustomerID
join Companies
on Customers.CustomerID = Companies.CompanyID
where DatePaid is null
union
select ReservationID, (FirstName + ' ' + LastName), DateOrdered
from ConferenceReservations
join Customers
on ConferenceReservations.CustomerID = Customers.CustomerID
join PrivateCustomers
on Customers.CustomerID = PrivateCustomers.CustomerID
join Participants
on PrivateCustomers.ParticipantID = Participants.ParticipantID
where DatePaid is null
GO
/****** Object: View [dbo].[CustomersWithPaidReservations] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[CustomersWithPaidReservations]
AS
SELECT CompanyName AS Customer, 'Company' AS 'Customer type', dbo.GetNumberOfPaidReservationForCustomer(Companies.Email) AS PaidReservations
FROM Customers
JOIN Companies
ON Customers.CustomerID = Companies.CompanyID
UNION
SELECT (FirstName + ' ' + LastName) AS Customer,
'Private customer' AS 'Customer type',
dbo.GetNumberOfPaidReservationForCustomer(Participants.Email) AS PaidReservations
FROM Customers
JOIN PrivateCustomers
ON Customers.CustomerID = PrivateCustomers.CustomerID
JOIN Participants
ON PrivateCustomers.ParticipantID = Participants.ParticipantID
GO
/****** Object: Table [dbo].[Conferences] Script Date: 22/01/2019 15:56:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Conferences](
[ConferenceID] [int] IDENTITY(0,1) NOT NULL,
[Name] [varchar](200) NOT NULL,
[StartDate] [date] NOT NULL,
[EndDate] [date] NOT NULL,
[BasePriceForDay] [money] NULL,
[StudentDiscount] [real] NULL,
[ParticipantsLimit] [int] NULL,
[Street] [varchar](74) NULL,
[HouseNumber] [varchar](5) NULL,
[AppartmentNumber] [int] NULL,
[CityID] [int] NULL,
[PostalCode] [char](6) NULL,
[CreatedOn] [date] NULL,
PRIMARY KEY CLUSTERED
(
[ConferenceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[ConferenceDayReservation] Script Date: 22/01/2019 15:56:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ConferenceDayReservation](
[DayReservationID] [int] IDENTITY(0,1) NOT NULL,
[ConferenceDayID] [int] NOT NULL,
[ReservedAdultSeats] [int] NOT NULL,
[ReservedStudentSeats] [int] NOT NULL,
[ReservationID] [int] NOT NULL,
CONSTRAINT [PK__Conferen__5572EBDB96C393BD] PRIMARY KEY CLUSTERED
(
[DayReservationID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [UQ_DAY_AND_RESERVATION] UNIQUE NONCLUSTERED
(
[ConferenceDayID] ASC,
[ReservationID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[ConferenceDays] Script Date: 22/01/2019 15:56:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ConferenceDays](
[ConferenceDayID] [int] IDENTITY(0,1) NOT NULL,
[ConferenceID] [int] NOT NULL,
[Date] [date] NOT NULL,
[DayOrdinal] [smallint] NULL,
CONSTRAINT [PK__Conferen__E57A6462D2FB2DE1] PRIMARY KEY CLUSTERED
(
[ConferenceDayID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [CHK_DAY_ORD_UNIQ] UNIQUE NONCLUSTERED
(
[ConferenceID] ASC,
[DayOrdinal] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: View [dbo].[ConferencesWithAvailablePlaces] Script Date: 22/01/2019 15:56:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[ConferencesWithAvailablePlaces]
AS
SELECT Conferences.ConferenceID, Name, DayOrdinal AS Day, ConferenceDays.Date AS 'Date', ParticipantsLimit AS 'Seat limit',
ISNULL(SUM(ReservedAdultSeats), 0) AS 'Reserved adult seats',
ISNULL(SUM(ReservedStudentSeats), 0) AS 'Reserved student seats',
ISNULL(SUM(ReservedAdultSeats + ReservedStudentSeats), 0) AS 'Total seats reserved',
ParticipantsLimit - ISNULL(SUM(ReservedAdultSeats + ReservedStudentSeats), 0) AS 'Available seats'
FROM Conferences
JOIN ConferenceDays
ON Conferences.ConferenceID = ConferenceDays.ConferenceID
LEFT JOIN ConferenceDayReservation
ON ConferenceDays.ConferenceDayID = ConferenceDayReservation.ConferenceDayID
WHERE Conferences.EndDate >= CONVERT(DATE, GETDATE())
GROUP BY Conferences.ConferenceID, Name, DayOrdinal, ParticipantsLimit, ConferenceDays.Date
GO
/****** Object: Table [dbo].[ConferenceDayWorkshops] Script Date: 22/01/2019 15:56:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ConferenceDayWorkshops](
[ConferenceDayWorkshopID] [int] IDENTITY(0,1) NOT NULL,
[ConferenceDayID] [int] NOT NULL,
[WorkshopID] [int] NOT NULL,
[StartTime] [time](7) NOT NULL,
[EndTime] [time](7) NOT NULL,
[Price] [money] NULL,
[ParticipantsLimit] [int] NULL,
CONSTRAINT [PK__Conferen__714B153C1B305831] PRIMARY KEY CLUSTERED
(
[ConferenceDayWorkshopID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[WorkshopReservation] Script Date: 22/01/2019 15:56:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[WorkshopReservation](
[WorkshopReservationID] [int] IDENTITY(0,1) NOT NULL,
[ConferenceDayWorkshopID] [int] NOT NULL,
[ConferenceDayReservationID] [int] NOT NULL,
[ReservedSeats] [int] NOT NULL,
PRIMARY KEY CLUSTERED
(
[WorkshopReservationID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [UQ_ONE_DAY_RESERV_ONE_WORKSH_RESERV] UNIQUE NONCLUSTERED
(
[ConferenceDayWorkshopID] ASC,
[ConferenceDayReservationID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Workshops] Script Date: 22/01/2019 15:56:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Workshops](
[WorkshopID] [int] IDENTITY(0,1) NOT NULL,
[Name] [varchar](200) NOT NULL,
[Description] [varchar](1000) NULL,
CONSTRAINT [PK__Workshop__7A008C2A4FD1EE19] PRIMARY KEY CLUSTERED
(
[WorkshopID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [UQ_NAME] UNIQUE NONCLUSTERED
(
[Name] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: View [dbo].[WorkshopsWithAvailablePlaces] Script Date: 22/01/2019 15:56:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[WorkshopsWithAvailablePlaces]
AS
SELECT Conferences.Name AS 'Conference Name',
Date, Workshops.Name AS 'Workshop Name', StartTime, EndTime, Price,
ConferenceDayWorkshops.ParticipantsLimit AS 'Seats limit', ISNULL(SUM(ReservedSeats),0) AS 'Reserved seats',
ConferenceDayWorkshops.ParticipantsLimit - ISNULL(SUM(ReservedSeats),0) AS 'Available Places',
Description
FROM Conferences
JOIN ConferenceDays
ON Conferences.ConferenceID = ConferenceDays.ConferenceID
JOIN ConferenceDayWorkshops
ON ConferenceDays.ConferenceDayID = ConferenceDayWorkshops.ConferenceDayID
JOIN Workshops
ON ConferenceDayWorkshops.WorkshopID = Workshops.WorkshopID
LEFT JOIN WorkshopReservation
ON ConferenceDayWorkshops.ConferenceDayWorkshopID = WorkshopReservation.ConferenceDayWorkshopID
GROUP BY Conferences.ConferenceID, Conferences.Name, Date, StartDate, StartTime,
EndTime, Workshops.Name, Price, ConferenceDayWorkshops.ParticipantsLimit, Description
GO
/****** Object: Table [dbo].[Students] Script Date: 22/01/2019 15:56:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Students](
[ParticipantID] [int] NOT NULL,
[StudentCardNumber] [varchar](10) NULL,
CONSTRAINT [PK__Student__7227997E8D9AA260] PRIMARY KEY CLUSTERED
(
[ParticipantID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[EmployeesOfCompanies] Script Date: 22/01/2019 15:56:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EmployeesOfCompanies](
[ParticipantID] [int] NOT NULL,
[CompanyID] [int] NOT NULL,
PRIMARY KEY CLUSTERED
(
[ParticipantID] ASC,
[CompanyID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [IX_EmployeesOfCompanies] UNIQUE NONCLUSTERED
(
[ParticipantID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[ConferenceDayParticipants] Script Date: 22/01/2019 15:56:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ConferenceDayParticipants](
[ConferenceDayParticipantID] [int] IDENTITY(0,1) NOT NULL,
[ConferenceDayReservationID] [int] NOT NULL,
[ParticipantID] [int] NOT NULL,
PRIMARY KEY CLUSTERED
(
[ConferenceDayParticipantID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [UQ_PARTICIPANT] UNIQUE NONCLUSTERED
(
[ConferenceDayReservationID] ASC,
[ParticipantID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: View [dbo].[ParticipantIdentificators] Script Date: 22/01/2019 15:56:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[ParticipantIdentificators]
AS
SELECT Name AS 'Conference Name', Date, FirstName, LastName, CompanyName, StudentCardNumber
FROM Conferences
JOIN ConferenceDays
ON Conferences.ConferenceID = ConferenceDays.ConferenceID
JOIN ConferenceDayReservation
ON ConferenceDays.ConferenceDayID = ConferenceDayReservation.ConferenceDayID
JOIN ConferenceDayParticipants
ON ConferenceDayReservation.DayReservationID = ConferenceDayParticipants.ConferenceDayReservationID
JOIN Participants
ON ConferenceDayParticipants.ParticipantID = Participants.ParticipantID
LEFT JOIN dbo.Students
ON Students.ParticipantID = Participants.ParticipantID
LEFT JOIN EmployeesOfCompanies
ON Participants.ParticipantID = EmployeesOfCompanies.ParticipantID
LEFT JOIN Companies
ON EmployeesOfCompanies.CompanyID = Companies.CompanyID
WHERE LastName IS NOT NULL AND date >= CONVERT(DATE, GETDATE())
GO
/****** Object: Table [dbo].[WorkshopParticipants] Script Date: 22/01/2019 15:56:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[WorkshopParticipants](
[ConferenceDayParticipantID] [int] NOT NULL,
[ConferenceDayWorkshopID] [int] NOT NULL,
PRIMARY KEY CLUSTERED
(