I have making room that has limit
of space. In this case suppose limit = 100
.
And I have total
that is when user join the room then total = total + 1
.
If user join the room then check
total <= limit
.If true then user can join the room if false can't.
So what I want to do for it in Mysql is
making before insert trigger for checking room is available before user join the room.
CREATE DEFINER = CURRENT_USER TRIGGER `relay_novel`.`RoomJoinedUsers_BEFORE_INSERT` BEFORE INSERT ON `RoomJoinedUsers` FOR EACH ROW
BEGIN
SET @total = 0;
SET @limit = 0;
SELECT @total := total FROM roomjoinedusersInfo WHERE roomId = NEW.roomId;
SELECT @limit := limit FROM rooms WHERE id = NEW.roomId;
IF (@total > @limit) {
// DON'T DO INSERT (HOW?)
}
END
My question is
How to do not inserting data into the database in before insert trigger?
Is there are better way to do it?
Please let me know if you need more info.
Thanks.