make a trigger in sql code example
Example 1: CREATE trigger SQL
CREATE OR REPLACE TRIGGER {trigger_name}
BEFORE | AFTER
INSERT | UPDATE | DELETE
ON {table_name}
(FOR EACH ROW)
{operation to be executed}
CREATE TRIGGER log_updates
AFTER INSERT OR UPDATE ON Person
FOR EACH ROW
INSERT INTO LogPerson(ts, IdPerson, surname)
VALUES(CURRENT_TIMESTAMP, NEW.id, NEW.surname);
Example 2: how use trigger in sql
CREATE TRIGGER Product_Details_tr
BEFORE INSERT ON Product_Details
FOR EACH ROW
SET NEW.User_ID = CURRENT_USER();