-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckBooking.sql
More file actions
24 lines (21 loc) · 1023 Bytes
/
CheckBooking.sql
File metadata and controls
24 lines (21 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
-- Task 2
-- For your second task, Little Lemon need you to create a stored procedure called CheckBooking
-- to check whether a table in the restaurant is already booked.
-- Creating this procedure helps to minimize the effort involved in repeatedly coding the same SQL statements.
-- The procedure should have two input parameters in the form of booking date and table number.
-- You can also create a variable in the procedure to check the status of each table.
DELIMITER //
CREATE PROCEDURE CheckBooking(IN booking_date DATETIME, IN table_number INT)
BEGIN
DECLARE bookedTable INT DEFAULT 0;
SELECT COUNT(bookedTable)
INTO bookedTable
FROM Bookings WHERE BookingDate = booking_date AND TableNumber = table_number;
IF bookedTable > 0 THEN
SELECT CONCAT("Table ", table_number, " is already booked") AS "Booking Status";
ELSE
SELECT CONCAT("Table ", table_number, " is not booked") AS "Booking Status";
END IF;
END //
DELIMITER ;
CALL CheckBooking("2022-11-12", 3);