Tag: trigger


Create trigger to update new field value before insertion

Let’s create a new MySQL trigger to update a new field value before insertion. The new value will be selected from another table. DELIMITER $$   CREATE TRIGGER trig_new_customer BEFORE INSERT ON customers FOR EACH ROW BEGIN DECLARE var1 VARCHAR(7); SELECT customer_next_code INTO var1 FROM next_codes; SET NEW.code = var1; END $$   DELIMITER ;DELIMITER …