0

I have faced syntax error during creating MySQL Trigger.

Create Trigger Count_McNum
before insert on tension
for each row
declare rowcount int ;
set rowcount = (select count(McNum) from tension where median is null) ;
if (rowcount >1000) 
then 
SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'Warning: rowcount> 1000!';
 END IF;
End

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 'declare rowcount int' at line 4

Husam Mohamed
4321 gold badge4 silver badges16 bronze badges
asked Apr 30, 2018 at 11:17

1 Answer 1

0

You're missing the small keyword BEGIN. And as you have multiple statements, you have to change the delimiter.

DELIMITER $$
Create Trigger Count_McNum
before insert on tension
for each row
BEGIN
declare rowcount int ;
set rowcount = (select count(McNum) from tension where median is null) ;
if (rowcount >1000) 
then 
SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'Warning: rowcount> 1000!';
 END IF;
End$$
DELIMITER ;
answered Apr 30, 2018 at 11:46

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.