我有下一个表:教师,教师,主题和科目。每个教师都有一个主题列表
我想使用checkthe faculty_subjects表格 - 每个教师不应该多次拥有相同的主题。因此,faculty_subjects
表格中的每条记录都有一对唯一的Faculty_idFaculty
- Subject_idSubject
。
我正在尝试添加下面列出的触发器:
DELIMITER $$
CREATE TRIGGER `Faculty_Subjects_BINS` BEFORE INSERT ON `Faculty_Subjects` FOR EACH ROW
BEGIN
-- throw exception when condition not satisfied
IF ( (NEW.`Subject_idSubject`= `Subject_idSubject`) AND (NEW.`Faculty_idFaculty`= `Faculty_idFaculty`)) THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'This faculty already add this subject as preliminary', MYSQL_ERRNO = 1001;
END IF;
END;
但我收到错误1109
或1054
。如何实现这一功能?
我正在使用MySQL数据库。