mysql - MySQL:触发器产生 Table not found 异常
问题描述
我有以下 2 个数据库表:DEPT(Dnumber、Dname、Fused、Mgr_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 Exception 并且当删除触发器时插入成功。
解决方案
推荐阅读
- python - 如何在python中将9个月零7天添加到日期“27-05-2018”
- security - 相互认证 - 设置、流程、验证
- rx-java2 - RxJava 运算符将随机大小的列表流分割成统一大小的列表,而不会丢失项目
- sass - 覆盖时未应用 sass 样式
- reactjs - 反应路由器错误
- c# - C# ASP.NET TempData 正在工作,但现在它不在 3 台计算机中的 2 台上
- c# - JSON 根据参数获取列表的值
- python - Python 的解释器在分配内存时会比较值吗?
- java - 如何在 Java mysql 中正确删除?
- python - 在 Ubuntu 18.04 上安装 Scrapy 时出现问题