Jump to content

Can't create Trigger. whats wrong in my code?


Recommended Posts

I try to create my first trigger.

Whats wrong with the code

 


Error Message

SQL query:

CREATE TRIGGER UpdMember BEFORE UPDATE ON TBMembers FOR EACH ROW BEGIN ;

 

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 '' at line 2

 


 

Here is the whole SQL query.

Have tryed to delete diffrent stuff but it seems to be a Error on first row.

 

 

CREATE TRIGGER UpdMember BEFORE UPDATE ON TBMembers FOR EACH ROW
BEGIN
DECLARE NTime DATETIME;
DECLARE NDay SMALLINT;
DECLARE NHour SMALLINT;
DECLARE NMin SMALLINT;
DECLARE NTurns INT;

SET NTime=DATE_SUB(NOW(),OLD.LastUpdated);
SET NDay=DAY(NTime);
SET NHour=HOUR(NTime);
SET NMin=MINUTE(NTime);
SET NMin=NDay*1440+NHour*60+NMin;

SET NTurns=FLOOR(NMin/5);
NMin=NMin-NTurns*5;
SET NEW.LastUpdated = DATE_SUB(NOW(),INTERVAL NMin MINUTE);
SET NEW.Turns=OLD.Turns+NTurns;
IF NEW.Turns>50 THEN SET NEW.Turns=50;
END

What do you meen.

 

; = the delimiter right?

 

Removed it.

 

CREATE TRIGGER Tabort BEFORE UPDATE ON TBMembers
FOR EACH ROW
BEGIN
SET NEW.LastUpdated = 5
END

 

Got this Message

#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 'END' at line 5

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.