I am having some issues with my database rn. In short, I want it so that when adding a row, if certain column with data type enum is equal to one of the choices, then a fixed VARCHAR can be added to the auto increase that is exemplified in the best answer to the question: How to make MySQL table primary key auto increment with some prefix, here is my current try:
CREATE TRIGGER tg_contracts_insert BEFORE INSERT ON contracts
FOR EACH ROW
BEGIN
IF NEW.dep := 'IT' THEN
SET NEW.dep :='IT'
END IF;
IF NEW.dep := 'Finanzas' THEN
SET NEW.dep :='FN'
END IF;
IF NEW.dep := 'RH' THEN
SET NEW.dep :='RH'
END IF;
IF NEW.dep := 'Mantenimiento' THEN
SET NEW.dep :='MN'
END IF;
IF NEW.dep := 'Cuartos' THEN
SET NEW.dep :='CT'
END IF;
INSERT INTO contracts_seq VALUES (NULL);
SET NEW.cid = CONCAT(NEW.dep, LPAD(LAST_INSERT_ID(), 5, '0'));
END
dep is the column with enum data type.
But, it says something about syntax, im not sure why (first time using triggers). Is there anything wrong?