0

I am trying to create trigger that ensures that the same shop_id should not repeat more than 3 times, and if user tries to add more than 3 records for the same shop_id, it will throw an error message. I have written the following trigger but its giving me error message.

  IF
    (sum(distinct(shop_id)) >3 )
    SET MESSAGE_TEXT := 'You cannot insert more than 3 Records';
    END IF;

Its giving me following error message.

    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

Kindly check this and guide me what i am doing wrong here.

enter image description here

1 Answer 1

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

SIGNAL Syntax

Sign up to request clarification or add additional context in comments.

1 Comment

And how should I use of that message in php?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.