Jump to content

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


Metalzed

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.