MySQL:触发器生成表未找到异常

时间:2018-04-30 21:15:16

标签: mysql database triggers

我有以下2个数据库表: DEPT( Dnumber ,Dname,成立,Mgr_ssn,预算) 员工( 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 Exception,当放下触发器时插入成功。

0 个答案:

没有答案