Trigger

A database trigger is procedural code that is automatically executed in response to certain events on a particular table or view in a database. The trigger is mostly used for keeping the integrity of the information on the database. For example, when a new record (representing a new worker) is added to the employees table, new records should be created also in the tables of the taxes, vacations, and salaries. Triggers are always created on DML statements only (INSERT, UPDATE & DELETE)

Example :-

CREATE TRIGGER insert_trigger BEFORE INSERT ON comments

FOR EACH ROW

BEGIN

SET NEW.comment = “This is my new comment”

END

Advertisements