简体   繁体   中英

get previous field value in trigger mysql

I have a trigger like this in MySQL:

DELIMITER $$
CREATE TRIGGER service_before_update BEFORE UPDATE ON service
FOR EACH ROW
BEGIN
    IF NEW.seatCount < (?) THEN
        SIGNAL SQLSTATE '12345';
    END IF;
END$$
DELIMITER ;

instead of (?) I want previous value of "seatCount" is there any easy way or I should use something like this(ServiceNo is a PRI key):

(SELECT seatCount FROM service WHERE serviceNo = NEW.serviceNo LIMIT 1) 

Yeah, it's super easy. OLD.seatCount should do what you want. http://dev.mysql.com/doc/refman/5.0/en/trigger-syntax.html has more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM