Domanda

I want to create a trigger which will be executed when a new row is about to be inserted if my condition is satisfied ( latest version = 1 ) all previous row will be updated with latest version = 0

CREATE TRIGGER remiseazero
BEFORE INSERT 
ON wp_stattype2_3_activite
FOR EACH ROW
BEGIN
IF NEW.latestversion = 1
THEN
update wp_stattype2_3_activite
set latestversion = 0 where typecas = new.typecas;
END IF;
END;$$

Error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 9

È stato utile?

Soluzione

Put delimiter. And remove ; after END.

DELIMITER $$
CREATE TRIGGER remiseazero
BEFORE INSERT 
ON wp_stattype2_3_activite
FOR EACH ROW
BEGIN
IF (NEW.latestversion = 1) THEN
    update wp_stattype2_3_activite set latestversion = 0 where typecas = NEW.typecas;
END IF;
END$$
DELIMITER ;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top