2014-10-10 55 views
0

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

回答

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

SIGNAL Syntax

+0

我应该如何在PHP中使用该消息的? – stack 2015-12-23 15:01:11