MySQL Trigger with Update

Posted by Matthew on Stack Overflow See other posts from Stack Overflow or by Matthew
Published on 2009-11-12T16:19:48Z Indexed on 2010/06/02 1:03 UTC
Read the original article Hit count: 382

Filed under:
|
|

I'm trying to update a row when it gets updated to keep one of the columns consistant,

CREATE TRIGGER user_country BEFORE UPDATE ON user_billing FOR EACH ROW
BEGIN
    IF NEW.billing_country = OLD.billing_country AND NEW.country_id != OLD.country_id THEN
    	SET NEW.billing_country = cms.country.country_name WHERE cms.country.country_id = NEW.country_id;
    END IF;
END

But I keep recieving error #1064, Is there a way to update a row based on another row's data when the row is getting updated?

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql