我有以下两个数据库表:dept(dnumber,dname,founded,mgr\u ssn,budget)employee(ssn,ename,bdate,dno,salary)
我想创建一个触发器,以确保每个部门的员工都不超过8人。这是我到目前为止写的
DELIMITER //
CREATE TRIGGER ensure_dept_count_on_insert BEFORE insert on `EMPLOYEE`
FOR EACH ROW
BEGIN
DECLARE maxCount integer;
set maxCount = (select count(*) as c from Employee where Dno = new.Dno);
if maxCount = 9
then SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'Department cannot have more than 8 employees';
end if;
END //
DELIMITER ;
问题是,当我插入employee时,它会给我table not found异常,当删除触发器时,插入成功。
暂无答案!
目前还没有任何答案,快来回答吧!