What is a trigger in MySQL?

CREATE TRIGGER log_deleted_student
AFTER DELETE ON students
FOR EACH ROW
INSERT INTO student_log (student_id, action)
VALUES (OLD.id, 'deleted');

Every time a row is deleted from students, the trigger adds a row to student_log. OLD is the row before the change and NEW is the row after it. Use triggers carefully, because they run hidden in the background.


Learn more about the similar topics:
Tutorials
MySQL Indexes
MySQL Views
MySQL Transactions
Exercises & Assignments
No Content Found.
Interview Questions & Answers
What is an index in MySQL?
What is a view in MySQL?
What is a transaction in MySQL? Explain ACID
What is a stored procedure in MySQL?
What is a trigger in MySQL?