22 lines
456 B
SQL
Executable File
22 lines
456 B
SQL
Executable File
CREATE TRIGGER IF NOT EXISTS CHK_Bookings_Insert BEFORE INSERT ON Bookings BEGIN
|
|
SELECT
|
|
RAISE (
|
|
FAIL,
|
|
"Reservation of table is not possible due to the existing reservation"
|
|
)
|
|
FROM
|
|
(
|
|
SELECT
|
|
datetime (NEW.reservation) AS new_res_dt,
|
|
datetime (reservation) AS res_dt,
|
|
datetime (reservation, time_reserve) AS reserved_until
|
|
FROM
|
|
Bookings
|
|
)
|
|
WHERE
|
|
new_res_dt >= res_dt
|
|
OR new_res_dt < reserved_until;
|
|
|
|
--
|
|
END;
|