delimiter //
create trigger check_number_of_occupied_beds
BEFORE INSERT
ON occupied_beds
FOR EACH ROW
BEGIN
DECLARE room_id int;
DECLARE allowed_number_of_beds INT;
DECLARE CUR1 CURSOR FOR
SELECT room.id, number_of_beds
FROM inserted INNER JOIN room ON inserted.id_room = room.id;
OPEN CUR1;
FETCH NEXT FROM CUR1 INTO @room_id, @allowed_number_of_beds;
WHILE @@FETCH_STATUS=0
BEGIN
IF @allowed_number_of_beds = (SELECT COUNT(occupied_beds.id_room)
FROM room INNER JOIN occupied_beds ON room.id = occupied_beds.id_room
WHERE room.id= @room_id, NOW() BETWEEN occupied_beds.since_ AND occupied_beds.to_
GROUP BY room.id);
rollback commit;
FETCH NEXT FROM CUR1 INTO @room_id, @allowed_number_of_beds;
END;
END;
Delimiter ;
Mysql даже не хочет добавить триггер. Нажимаю на выполнить запрос и ничего не происходит.