I am creating a room reservation in php.
I have two tables:
table RESERVE
- reserve_id
- room_id
- room_reserve_qty
- checkout
table ROOM
- room_id
- room_qty
when the “checkout” date reached the date today,that row in the reserve table will be deleted.Actually I already have the event for that :
DROP EVENT `auto_delete_chckout`;
CREATE DEFINER=`root`@`localhost`
EVENT `auto_delete_chckout`
ON SCHEDULE EVERY 1 MINUTE STARTS '2013-01-26 13:09:15'
ON COMPLETION NOT PRESERVE ENABLE DO
DELETE FROM reserve WHERE checkout <= CURDATE()
so my question is :
If a reservation is being deleted , its room_reserve_qty must be added in the room_qty in room table.
First of all you probably don’t need to fire your event every minute, since you check only for a date part. You might want to do that once a day.
Secondly I would put updating
room_qtylogic in a trigger. That way no matter how you delete your reservation, yourroom_qtywill be correct.Your trigger might look like this
Your
DELETEcode stays intact when you use a trigger.