如何从触发器的输出中返回错误消息?

时间:2014-10-10 08:12:48

标签: php mysql sql database

我正在尝试创建触发器,以确保相同的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

请检查一下,并指导我在这里做错了什么。

enter image description here

1 个答案:

答案 0 :(得分:2)

SIGNAL SQLSTATE '45000'
       SET MESSAGE_TEXT = 'You cannot insert more than 3 Records';

SIGNAL Syntax

相关问题