salix/db/routines/vn/triggers/client_afterUpdate.sql

15 lines
383 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_afterUpdate`
AFTER UPDATE ON `client`
FOR EACH ROW
BEGIN
IF !(NEW.defaultAddressFk <=> OLD.defaultAddressFk) THEN
UPDATE `address` SET isDefaultAddress = FALSE
WHERE clientFk = NEW.id;
UPDATE `address` SET isDefaultAddress = TRUE
WHERE id = NEW.defaultAddressFk;
END IF;
END$$
DELIMITER ;