salix/db/install/changes/8-clientAfterUpdate.sql

21 lines
582 B
SQL

/* Añadir a producción cuando se suba salix */
DROP TRIGGER IF EXISTS vn2008.ClientesAfterUpdate;
USE vn2008;
DELIMITER $$
$$
CREATE DEFINER=`root`@`%` TRIGGER `vn2008`.`ClientesAfterUpdate`
AFTER UPDATE ON `Clientes`
FOR EACH ROW
BEGIN
IF NEW.default_address AND (NEW.default_address != OLD.default_address) THEN
UPDATE Consignatarios SET predeterminada = FALSE
WHERE Id_cliente = NEW.Id_cliente;
UPDATE Consignatarios SET predeterminada = TRUE
WHERE Id_consigna = NEW.default_address;
END IF;
END$$
DELIMITER ;
USE vn;