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

14 lines
428 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmap_beforeUpdate`
BEFORE UPDATE ON `roadmap`
FOR EACH ROW
BEGIN
CALL vehicle_checkNumberPlate(NEW.tractorPlate, NULL);
CALL vehicle_checkNumberPlate(NEW.trailerPlate, NULL);
IF NEW.driver1Fk IS NOT NULL THEN
SET NEW.driverName = (SELECT firstName FROM worker WHERE id = NEW.driver1Fk);
ELSE
SET NEW.driverName = NULL;
END IF;
END$$
DELIMITER ;