-
Notifications
You must be signed in to change notification settings - Fork 1
/
procedures.sql
846 lines (760 loc) · 19.2 KB
/
procedures.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
-- dodawanie kategorii
CREATE PROCEDURE AddCategoryProcedure
@CategoryName varchar(64)
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF EXISTS(
SELECT *
FROM Categories
WHERE @CategoryName = CategoryName
)
BEGIN
;
THROW 52000, 'Kategoria jest już dodana', 1 -- nwm o co chodzi z tymi numerami
end
DECLARE @CategoryID INT
SELECT @CategoryID = ISNULL(MAX(CategoryID), 0) + 1
FROM Categories
INSERT INTO Categories(CategoryID, CategoryName)
VALUES(@CategoryID, @CategoryName);
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Błąd dodawania kategorii: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
-- usuwanie kategorii
CREATE PROCEDURE RemoveCategoryProcedure
@CategoryName varchar(64)
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF EXISTS(
SELECT *
FROM Categories
WHERE @CategoryName = CategoryName
)
BEGIN
;
DELETE FROM Categories WHERE @CategoryName = CategoryName
end
ELSE
THROW 52000, 'Kategoria jest już dodana', 1 -- nwm o co chodzi z tymi numerami
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Błąd usuwania kategorii: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
-- dodawanie produktu
CREATE PROCEDURE AddProductProcedure
@CategoryName varchar(64),
@Name varchar(64)
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF EXISTS(
SELECT *
FROM Products
WHERE ProductName = @Name
)
BEGIN
;
THROW 52000, 'Potrawa jest już w bazie', 1
END
IF NOT EXISTS(
SELECT *
FROM Categories
WHERE CategoryName = @CategoryName
)
BEGIN
;
THROW 52000, 'Brak kategorii', 1 --można by jakoś wtedy dodać kategorie razem z produktem jak rzuci taki błąd, ale wtedy np: 'ser', 'nabial' utworzy nową kategoria zamiast wpaść do 'nabiał'
END
DECLARE @CategoryID INT
SELECT @CategoryID = CategoryID
FROM Categories
WHERE CategoryName = @CategoryName
DECLARE @ProductID INT
SELECT @ProductID = ISNULL(MAX(ProductID), 0) + 1
FROM Products
INSERT INTO Products(ProductID, ProductName, CategoryID)
VALUES (@ProductID, @Name, @CategoryID);
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Błąd dodawania produktu kategorii: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
-- usunięcie produktu
CREATE PROCEDURE RemoveProductProcedure
@CategoryID int,
@Name varchar(64)
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF EXISTS(
SELECT *
FROM Products
WHERE ProductName = @Name
)
BEGIN
;
DELETE FROM Products WHERE @CategoryID = Products.CategoryID AND @Name=ProductName
END
IF NOT EXISTS(
SELECT *
FROM Categories
WHERE @CategoryID = CategoryID
)
BEGIN
;
THROW 52000, 'Brak kategorii', 1
END
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Błąd usuwania produktu: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
--dodawanie stolika do restauracji
CREATE PROCEDURE AddTableProcedure
@capacity int
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
DECLARE @DinigTableID INT
SELECT @DinigTableID = ISNULL(MAX(DiningTables.DiningTableID), 0) + 1
FROM DiningTables
INSERT INTO DiningTables(DiningTableID, NumberOfSeats)
VALUES(@DinigTableID, @capacity);
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Błąd dodawania stolika: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
--usuwanie stolika z restauracji
CREATE PROCEDURE RemoveTableProcedure
@tableID int
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF EXISTS(
SELECT *
FROM DiningTables
WHERE DiningTableID = @tableID
)
BEGIN
;
DELETE FROM DiningTables WHERE @tableID = DiningTableID
END
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Błąd usuwania stolika: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
-- dodawanie pracownika
CREATE PROCEDURE AddEmployeeProcedure
@FirstName varchar(64),
@LastName varchar(64),
@Occupation varchar(64),
@Street varchar(64),
@Country varchar(64),
@City varchar(64),
@PostCode varchar(16),
@Phone char(9),
@Email varchar(64)
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF EXISTS(
SELECT *
FROM RestaurantEmployees
WHERE FirstName = @FirstName AND LastName = @LastName AND Occupation = @Occupation AND Street=@Street AND Country = @Country AND City = @City AND PostCode=@PostCode AND Phone = @Phone AND Email=@Email
)
BEGIN
;
THROW 52000, 'Pracownik jest już w bazie', 1
END
DECLARE @RestaurantEmployeeID INT
SELECT @RestaurantEmployeeID = ISNULL(MAX(RestaurantEmployeeID), 0) + 1
FROM RestaurantEmployees
INSERT INTO RestaurantEmployees(RestaurantEmployeeID,FirstName, LastName, Occupation, Street, Country, City, PostCode,Phone,Email)
VALUES (@RestaurantEmployeeID, @FirstName, @LastName, @Occupation, @Street, @Country, @City, @PostCode,@Phone,@Email);
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Błąd dodawania pracownika: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
-- usunięcie pracownika
CREATE PROCEDURE RemoveEmployeeProcedure
@RestaurantEmployeeID INT
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF EXISTS(
SELECT *
FROM RestaurantEmployees
WHERE RestaurantEmployeeID = @RestaurantEmployeeID
)
BEGIN
;
DELETE FROM RestaurantEmployees
WHERE @RestaurantEmployeeID = RestaurantEmployeeID
END
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Błąd usuwania pracownika: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
-- AddMenuProcedure
CREATE PROCEDURE AddMenuProcedure
@MenuName varchar(64),
@FromTime datetime,
@ToTime datetime
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF EXISTS(
SELECT *
FROM Menu
WHERE MenuName = @MenuName
)
BEGIN
;
THROW 52000, 'Menu with provided name is already in the database', 1
END
DECLARE @MenuID INT
SELECT @MenuID = ISNULL(MAX(MenuID), 0) + 1
FROM Menu
INSERT INTO Menu(MenuID, MenuName, FromTime, ToTime)
VALUES (@MenuID, @MenuName, @FromTime, @ToTime);
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Error adding menu: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
-- RemoveMenuProcedure
CREATE PROCEDURE RemoveMenuProcedure
@MenuID int
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF EXISTS(
SELECT *
FROM Menu
WHERE MenuID = @MenuID
)
BEGIN
;
DELETE FROM Menu WHERE @MenuID = MenuID
END
ELSE
BEGIN
;
THROW 52000, 'Menu with provided ID does not exist', 1
END
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Error removing menu: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
-- AddIngredientToWarehouse
CREATE PROCEDURE AddIngredientToWarehouse
@IngredientName varchar(64),
@QuantityLeft int
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF EXISTS(
SELECT *
FROM IngredientsWarehouse
WHERE IngredientName = @IngredientName
)
BEGIN
;
THROW 52000, 'Ingredient with provided name is already in the database', 1
END
DECLARE @IngredientID INT
SELECT @IngredientID = ISNULL(MAX(IngredientID), 0) + 1
FROM IngredientsWarehouse
INSERT INTO IngredientsWarehouse(IngredientID, IngredientName, QuantityLeft)
VALUES (@IngredientID, @IngredientName, @QuantityLeft);
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Error adding ingredient: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
-- RemoveIngredientFromWarehouse
CREATE PROCEDURE RemoveIngredientFromWarehouse
@IngredientID int
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF EXISTS(
SELECT *
FROM IngredientsWarehouse
WHERE IngredientID = @IngredientID
)
BEGIN
;
DELETE FROM IngredientsWarehouse WHERE IngredientID = @IngredientID
END
ELSE
BEGIN
;
THROW 52000, 'Ingredient with provided ID does not exist', 1
END
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Error removing Ingredient: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
-- AddIngredientToProduct
CREATE PROCEDURE AddIngredientToProduct
@ProductID int,
@IngredientID int
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF EXISTS(
SELECT *
FROM ProductIngredients
WHERE IngredientID = @IngredientID
AND ProductID = @ProductID
)
BEGIN
;
THROW 52000, 'This productID-ingredientID pair already exists', 1
END
IF NOT EXISTS(
SELECT *
FROM Products
WHERE ProductID = @ProductID
)
BEGIN
;
THROW 52000, 'Product with provided ID does not exist', 1
END
IF NOT EXISTS(
SELECT *
FROM IngredientsWarehouse
WHERE IngredientID = @IngredientID
)
BEGIN
;
THROW 52000, 'Ingredient with provided ID does not exist', 1
END
INSERT INTO ProductIngredients(ProductID, IngredientID)
VALUES (@ProductID, @IngredientID);
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Error adding productID-ingredientID pair: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
-- RemoveIngredientFromProduct
CREATE PROCEDURE RemoveIngredientFromProduct
@IngredientID int,
@ProductID int
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF EXISTS(
SELECT *
FROM ProductIngredients
WHERE IngredientID = @IngredientID
AND ProductID = @ProductID
)
BEGIN
;
DELETE FROM ProductIngredients WHERE IngredientID = @IngredientID AND ProductID = @ProductID
END
ELSE
BEGIN
;
THROW 52000, 'Provided productID-ingredientID pair does not exist', 1
END
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Error removing productID-ingredientID pair: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
-- AddProductToMenuProcedure
CREATE PROCEDURE AddProductToMenuProcedure
@ProductID int,
@MenuID int
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF EXISTS(
SELECT *
FROM MenuDetails
WHERE MenuID = @MenuID
AND ProductID = @ProductID
)
BEGIN
;
THROW 52000, 'This productID-menuID pair already exists', 1
END
IF NOT EXISTS(
SELECT *
FROM Products
WHERE ProductID = @ProductID
)
BEGIN
;
THROW 52000, 'Product with provided ID does not exist', 1
END
IF NOT EXISTS(
SELECT *
FROM Menu
WHERE MenuID = @MenuID
)
BEGIN
;
THROW 52000, 'Menu with provided ID does not exist', 1
END
INSERT INTO MenuDetails(MenuID, ProductID)
VALUES (@MenuID, @ProductID);
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Error adding productID-menuID pair: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
-- RemoveProductFromMenuProcedure
CREATE PROCEDURE RemoveProductFromMenuProcedure
@MenuID int,
@ProductID int
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF EXISTS(
SELECT *
FROM MenuDetails
WHERE MenuID = @MenuID
AND ProductID = @ProductID
)
BEGIN
;
DELETE FROM MenuDetails WHERE MenuID = @MenuID AND ProductID = @ProductID
END
ELSE
BEGIN
;
THROW 52000, 'Provided productID-menuID pair does not exist', 1
END
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Error removing productID-menuID pair: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
-- AddProductToOrderProcedure
CREATE PROCEDURE AddProductToOrder
@ProductID int,
@OrderID int,
@Quantity int
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF EXISTS(
SELECT *
FROM OrderDetails
WHERE OrderID = @OrderID
AND ProductID = @ProductID
)
BEGIN
;
THROW 52000, 'This productID-orderID pair already exists', 1
END
IF NOT EXISTS(
SELECT *
FROM Products
WHERE ProductID = @ProductID
)
BEGIN
;
THROW 52000, 'Product with provided ID does not exist', 1
END
IF NOT EXISTS(
SELECT *
FROM Orders
WHERE OrderID = @OrderID
)
BEGIN
;
THROW 52000, 'Order with provided ID does not exist', 1
END
INSERT INTO OrderDetails(OrderID, ProductID,Quantity)
VALUES (@OrderID, @ProductID,@Quantity);
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Error adding productID-orderID pair: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
-- RemoveProductFromOrderProcedure
CREATE PROCEDURE RemoveProductFromOrder
@OrderID int,
@ProductID int,
@Quantity int
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF EXISTS(
SELECT *
FROM OrderDetails
WHERE OrderID = @OrderID
AND ProductID = @ProductID
AND Quantity = @Quantity
)
BEGIN
;
DELETE FROM OrderDetails WHERE OrderID = @OrderID AND ProductID = @ProductID AND Quantity = @Quantity
END
ELSE
BEGIN
;
THROW 52000, 'Provided productID-orderID pair does not exist', 1
END
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Error removing productID-orderID pair: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
-- dodawanie klienta
CREATE PROCEDURE AddCustomerProcedure
@Street varchar(64),
@Country varchar(64),
@City varchar(64),
@PostCode varchar(16),
@Phone varchar(16),
@Email varchar(64)
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF EXISTS(
SELECT *
FROM Customers
WHERE Street = @Street AND Country = @Country AND City=@City AND PostCode = @PostCode AND Phone = @Phone AND Email=@Email
)
BEGIN
;
THROW 52000, 'Klient jest już w bazie', 1
END
DECLARE @CustomerID INT
SELECT @CustomerID = ISNULL(MAX(CustomerID), 0) + 1
FROM Customers
INSERT INTO Customers(CustomerID,Street, Country, City, PostCode, Phone, Email)
VALUES (@CustomerID, @Street, @Country, @City, @PostCode, @Phone, @Email);
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Błąd dodawania klienta: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
-- usunięcie pracownika
CREATE PROCEDURE RemoveCustomerProcedure
@CustomerID INT
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF EXISTS(
SELECT *
FROM Customers
WHERE CustomerID = @CustomerID
)
BEGIN
;
DELETE FROM Customers
WHERE CustomerID = @CustomerID
END
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Błąd usuwania klienta: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
--dodanie dla danej zmiennej nowego czasu, aktualizacja dotychczasowej komorki z NULL'em w toTime
CREATE PROCEDURE updateDiscountProcedure
@VariableType varchar(3),
@VariableValue int
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF NOT EXISTS(
SELECT *
FROM VariablesData
WHERE VariableType = @VariableType
)
BEGIN
;
THROW 52000, 'this type of discount does not exist', 1
END
IF EXISTS(
SELECT * FROM VariablesData WHERE VariableType = @VariableType AND ToTime IS NULL
)
BEGIN
;
UPDATE VariablesData SET ToTime = GETDATE() WHERE ToTime IS NULL AND VariableType = @VariableType
END
INSERT INTO VariablesData(FromTime,ToTime,VariableType,VariableValue)
VALUES (GETDATE(),NULL,@VariableType,@VariableValue);
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Błąd aktualizacji rabatu: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
-- AddReservationProcedure
CREATE PROCEDURE AddReservationProcedure
@FromTime datetime ,
@ToTime datetime ,
@Seats int,
@DiningTableID int,
@OrderID int
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF NOT EXISTS(
SELECT OrderID FROM Orders WHERE OrderID = @OrderID
)
BEGIN
;
THROW 52000, 'Provided OrderID is not in the database', 1
END
IF NOT EXISTS(
SELECT DiningTableID FROM DiningTables WHERE DiningTableID = @DiningTableID
)
BEGIN
;
THROW 52000, 'Provided DiningTableID is not in the database', 1
END
IF EXISTS(
SELECT *
FROM Reservation
WHERE OrderID = @OrderID AND DiningTableID = @DiningTableID
)
BEGIN
;
THROW 52000, 'Reservation with provided OrderID and DiningTableID is already in the database', 1
END
DECLARE @ReservationID INT
SELECT @ReservationID = ISNULL(MAX(ReservationID), 0) + 1
FROM Reservation
INSERT INTO Reservation(ReservationID, FromTime, ToTime, Seats,DiningTableID,OrderID)
VALUES (@ReservationID, @FromTime, @ToTime, @Seats,@DiningTableID,@OrderID);
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Error adding menu: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go
-- RemoveReservationProcedure
CREATE PROCEDURE RemoveReservationProcedure
@ReservationID int
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
IF EXISTS(
SELECT *
FROM Reservation
WHERE ReservationID = @ReservationID
)
BEGIN
;
DELETE FROM Reservation WHERE @ReservationID = ReservationID
END
ELSE
BEGIN
;
THROW 52000, 'Reservation with provided ID does not exist', 1
END
END TRY
BEGIN CATCH
DECLARE @errormsg nvarchar(2048) =
'Error removing menu: ' + ERROR_MESSAGE();
THROW 52000, @errormsg, 1;
END CATCH
END
go