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

17 lines
437 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketDms_beforeDelete`
BEFORE DELETE ON `ticketDms`
FOR EACH ROW
BEGIN
UPDATE dms
SET dmsTypeFk = (SELECT id
FROM dmsType
WHERE `code` = 'trash'
)
WHERE id = OLD.dmsFk AND ( SELECT IF(COUNT(*) > 0, FALSE, TRUE)
FROM ticketDms
WHERE dmsFk = OLD.dmsFk
) ;
END$$
DELIMITER ;