Skip to content

OLD

CREATE TRIGGER example_trigger
BEFORE UPDATE ON student_table
FOR EACH ROW
BEGIN
IF NEW.age < OLD.age THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Age can not be reduced';
END IF;
END;
Query OK, 0 rows affected (0.01 sec)

In this example, a trigger named ‘example_trigger’ is created on ‘student_table’. This trigger fires before an update operation on the ‘student_table’. If the new age value in the update statement is less than the old age value, the update operation is aborted and a message ‘Age can not be reduced’ is displayed. The ‘OLD’ keyword is used to refer to column values as they were before the UPDATE operation.