How to create a trigger in MySQL Explain with example ?
In MySQL, a trigger corresponds to a set of actions running automatically when a particular change operation like SQL INSERT, UPDATE, or DELETE query is performed on a table.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | CREATE TRIGGER data_backup BEFORE UPDATE ON users FOR EACH ROW BEGIN IF NEW.amount < 0 THEN SET NEW.amount = 0; ELSEIF NEW.amount > 100 THEN SET NEW.amount = 100; END IF; END;// |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.