Add modify bookings scripts and results

This commit is contained in:
2024-11-18 15:52:59 +01:00
parent 0d75c1c035
commit 936c1d3ed4
4 changed files with 145 additions and 0 deletions

15
sql/add_booking.sql Normal file
View File

@@ -0,0 +1,15 @@
-- modify bookings - task 1
-- changes:
-- changed BookingDate (Reserved) data type from date to datetime, because I assumed that Little Lemon
-- allows wants bookings per day and table - a table is considered blocked for 2 hours
-- added EmployeeID input parameter
-- noqa: disable=CP03,LT02,RF03
create procedure AddBooking (
in BookingID int, in Reserved datetime, in TableNumber int, in CustomerID int, in EmployeeID int
)
begin
insert into Bookings (BookingID, Reserved, TableNumber, CustomerID, EmployeeID) values (
BookingID, Reserved, TableNumber, CustomerID, EmployeeID
);
select concat("New booking added") as Confirmation;
end

13
sql/cancel_booking.sql Normal file
View File

@@ -0,0 +1,13 @@
-- modify bookings - task 3
-- add and update bookings - task 3
-- noqa: disable=CP03,LT02,RF03
create procedure CancelBooking (in BookingID int)
begin
delete from Bookings as B
where B.BookingID = BookingID;
if row_count() = 1 then
select concat("Booking ", BookingID, " cancelled") as Confirmation;
else
select concat("Booking ", BookingID, " not cancelled - missing booking") as Confirmation;
end if;
end

View File

@@ -0,0 +1,101 @@
# Task 1
> delimiter $
> source ./add_booking.sql
> delimiter ;
> call AddBooking(20, "2024-11-19 19:00:00", 3, 1, 2)
+-------------------+
| Confirmation |
+-------------------+
| New booking added |
+-------------------+
> select * from `Bookings` where `BookingID` = 20
+-----------+---------------------+-------------+------------+------------+
| BookingID | Reserved | TableNumber | CustomerID | EmployeeID |
+-----------+---------------------+-------------+------------+------------+
| 20 | 2024-11-19 19:00:00 | 3 | 1 | 2 |
+-----------+---------------------+-------------+------------+------------+
# Task 2
> delimiter $
> source ./update_booking.sql
> delimiter ;
> call UpdateBooking(20, date_sub((select Reserved from `Bookings` where `BookingID` = 20), interval 1 day))
+--------------------+
| Confirmation |
+--------------------+
| Booking 20 updated |
+--------------------+
> select * from `Bookings` where `BookingID` = 20;
+-----------+---------------------+-------------+------------+------------+
| BookingID | Reserved | TableNumber | CustomerID | EmployeeID |
+-----------+---------------------+-------------+------------+------------+
| 20 | 2024-11-18 19:00:00 | 3 | 1 | 2 |
+-----------+---------------------+-------------+------------+------------+
> call UpdateBooking(21, "2024-11-18 15:00:00")
+---------------------------------------------+
| Confirmation |
+---------------------------------------------+
| Booking 21 wasn't updated - missing booking |
+---------------------------------------------+
> select * from `Bookings` where `BookingID` = 21
+-----------+----------+-------------+------------+------------+
| BookingID | Reserved | TableNumber | CustomerID | EmployeeID |
+-----------+----------+-------------+------------+------------+
+-----------+----------+-------------+------------+------------+
# Task 3
> delimiter $
> source ./cancel_booking.sql
> delimiter ;
> call CancelBooking(20)
+----------------------+
| Confirmation |
+----------------------+
| Booking 20 cancelled |
+----------------------+
> select * from `Bookings`
+-----------+---------------------+-------------+------------+------------+
| BookingID | Reserved | TableNumber | CustomerID | EmployeeID |
+-----------+---------------------+-------------+------------+------------+
| 1 | 2024-11-14 18:00:00 | 1 | 3 | 1 |
| 2 | 2024-11-14 19:30:00 | 2 | 2 | 1 |
| 3 | 2024-11-14 18:45:00 | 3 | 4 | 1 |
| 4 | 2024-11-14 19:15:00 | 4 | 1 | 2 |
| 5 | 2024-11-14 18:30:00 | 5 | 6 | 2 |
| 6 | 2024-11-14 19:00:00 | 6 | 5 | 2 |
| 7 | 2024-11-15 18:15:00 | 1 | 7 | 5 |
| 8 | 2024-11-15 19:45:00 | 2 | 8 | 5 |
| 9 | 2024-11-15 18:30:00 | 3 | 9 | 2 |
| 10 | 2024-11-15 19:00:00 | 4 | 10 | 5 |
| 11 | 2022-10-14 18:00:00 | 5 | 1 | 1 |
| 12 | 2022-11-12 19:30:00 | 3 | 3 | 1 |
| 13 | 2022-10-11 18:45:00 | 2 | 2 | 1 |
| 14 | 2022-10-13 19:15:00 | 2 | 1 | 1 |
| 15 | 2022-11-12 17:15:00 | 3 | 4 | 1 |
+-----------+---------------------+-------------+------------+------------+
> call CancelBooking(21)
+--------------------------------------------+
| Confirmation |
+--------------------------------------------+
| Booking 21 not cancelled - missing booking |
+--------------------------------------------+
> select * from `Bookings`
+-----------+---------------------+-------------+------------+------------+
| BookingID | Reserved | TableNumber | CustomerID | EmployeeID |
+-----------+---------------------+-------------+------------+------------+
| 1 | 2024-11-14 18:00:00 | 1 | 3 | 1 |
| 2 | 2024-11-14 19:30:00 | 2 | 2 | 1 |
| 3 | 2024-11-14 18:45:00 | 3 | 4 | 1 |
| 4 | 2024-11-14 19:15:00 | 4 | 1 | 2 |
| 5 | 2024-11-14 18:30:00 | 5 | 6 | 2 |
| 6 | 2024-11-14 19:00:00 | 6 | 5 | 2 |
| 7 | 2024-11-15 18:15:00 | 1 | 7 | 5 |
| 8 | 2024-11-15 19:45:00 | 2 | 8 | 5 |
| 9 | 2024-11-15 18:30:00 | 3 | 9 | 2 |
| 10 | 2024-11-15 19:00:00 | 4 | 10 | 5 |
| 11 | 2022-10-14 18:00:00 | 5 | 1 | 1 |
| 12 | 2022-11-12 19:30:00 | 3 | 3 | 1 |
| 13 | 2022-10-11 18:45:00 | 2 | 2 | 1 |
| 14 | 2022-10-13 19:15:00 | 2 | 1 | 1 |
| 15 | 2022-11-12 17:15:00 | 3 | 4 | 1 |
+-----------+---------------------+-------------+------------+------------+

16
sql/update_booking.sql Normal file
View File

@@ -0,0 +1,16 @@
-- modify bookings - task 2
-- changes:
-- changed BookingDate (Reserved) data type from date to datetime, because I assumed that Little Lemon
-- allows wants bookings per day and table - a table is considered blocked for 2 hours
-- noqa: disable=CP03,LT02,RF03
create procedure UpdateBooking (in BookingID int, in Reserved datetime)
begin
update Bookings as B
set B.Reserved = Reserved
where B.BookingID = BookingID;
if row_count() = 1 then
select concat("Booking ", BookingID, " updated") as Confirmation;
else
select concat("Booking ", BookingID, " wasn't updated - missing booking") as Confirmation;
end if;
end