i want to create trigger after update to delete row on specific condition i did find similar question here but the code won't work with me.
This is what i try to do :
DELIMITER $$
CREATE TRIGGER delete_rejected_friendship
AFTER UPDATE
ON friendship FOR EACH ROW
BEGIN
IF Update(RequestState)
BEGIN
DELETE FROM friendship WHERE RequestState = 'reject'
END
END
END$$
DELIMITER ;
This is the error which appears:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Update(RequestState) Begin DELETE FROM friendship WHERE Reque' at line 9`
so i have friendship table that have three columns userID , friendID and RequestState. this table represent friendship relationship and friendship request state. if RequestState= accept then they are friends and if RequestState = reject the row should be deleted.
Edit : if update(requeststate) for if the column = requeststate updated (changed from 'waiting' state to either 'accept' or 'reject' state) then the other condition in delete statement (WHERE RequestState = 'reject') to specify only change to 'reject' state