我正在尝试创建触发器,以确保相同的 shop_id
重复次数不会超过 3 次,并且如果用户尝试为相同的 shop_id
添加超过 3 条记录>,它会抛出错误消息。
我已经编写了以下触发器,但它给了我错误消息。
IF
(sum(distinct(shop_id)) >3 )
SET MESSAGE_TEXT := 'You cannot insert more than 3 Records';
END IF;
它给了我以下错误消息。
MySQL said: #1064 - You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version
for the right syntax to use near 'SET MESSAGE_TEXT
:= 'check constraint on
请检查这一点并指导我在这里做错了什么。
最佳答案
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'You cannot insert more than 3 Records';
关于php - 如何在触发器的输出中返回错误消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26294761/