Last active
June 13, 2024 17:00
-
-
Save nasirdn/aac467bc3eb7bf85cc0b615f4d6b4dba to your computer and use it in GitHub Desktop.
Создание триггера - проект бд
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TRIGGER IF EXISTS `project_bd`.`employee_BEFORE_INSERT`; | |
DELIMITER $$ | |
USE `project_bd`$$ | |
CREATE DEFINER = CURRENT_USER TRIGGER `project_bd`.`employee_BEFORE_INSERT` BEFORE INSERT ON `employee` FOR EACH ROW | |
BEGIN | |
if new.rank <> 'Отсутствует' then | |
signal sqlstate '45000' set message_text = 'Звание у работника должно отсутствовать.'; | |
end if; | |
END$$ | |
DELIMITER ; | |
-------- | |
DROP TRIGGER IF EXISTS `project_bd`.`attestation_BEFORE_INSERT`; | |
DELIMITER $$ | |
USE `project_bd`$$ | |
CREATE DEFINER=`root`@`localhost` TRIGGER `attestation_BEFORE_INSERT` BEFORE INSERT ON `attestation` FOR EACH ROW BEGIN | |
if new.status_to_work_SIZOD = 'не готов' and new.no_SIZOD_reason is NULL then | |
signal sqlstate '45000' set message_text = 'Укажите причину не готовности к использованию СИЗОД'; | |
end if; | |
if new.status_to_work_SIZOD = 'готов' and (new.date_of_admis_order is NULL or new.num_of_admis_order is NULL) then | |
signal sqlstate '45000' set message_text = 'Для прошедших аттестацию укажите дату и номер приказа о допуске.'; | |
end if; | |
if new.status_to_work_SIZOD = 'не готов' and (new.date_of_admis_order is NOT NULL or new.num_of_admis_order is NOT NULL) then | |
signal sqlstate '45000' set message_text = 'Для сотрудников, не прошедших аттестацию, дата и номер приказа о допуске не указывается.'; | |
end if; | |
if new.status_to_work_SIZOD = 'готов' and (new.no_SIZOD_reason is NOT NULL) then | |
signal sqlstate '45000' set message_text = 'Для прошедших аттестацию причина не готовности не указывается'; | |
end if; | |
END$$ | |
DELIMITER ; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment