Metalzed Posted October 22, 2010 Share Posted October 22, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/216605-cant-create-trigger-whats-wrong-in-my-code/ Share on other sites More sharing options...
Metalzed Posted October 22, 2010 Author Share Posted October 22, 2010 Tryed another Trigger This isn't working. Whats wrong. CREATE TRIGGER Tabort BEFORE UPDATE ON TBMembers FOR EACH ROW BEGIN SET NEW.LastUpdated = 5; END Quote Link to comment https://forums.phpfreaks.com/topic/216605-cant-create-trigger-whats-wrong-in-my-code/#findComment-1125392 Share on other sites More sharing options...
fenway Posted October 23, 2010 Share Posted October 23, 2010 Probably the delimiter. Quote Link to comment https://forums.phpfreaks.com/topic/216605-cant-create-trigger-whats-wrong-in-my-code/#findComment-1125664 Share on other sites More sharing options...
Metalzed Posted October 23, 2010 Author Share Posted October 23, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/216605-cant-create-trigger-whats-wrong-in-my-code/#findComment-1125678 Share on other sites More sharing options...
fenway Posted October 30, 2010 Share Posted October 30, 2010 Well, technically, you don't need a begin/end for such a simple statement. Quote Link to comment https://forums.phpfreaks.com/topic/216605-cant-create-trigger-whats-wrong-in-my-code/#findComment-1128483 Share on other sites More sharing options...
Metalzed Posted November 2, 2010 Author Share Posted November 2, 2010 Yes. But I will have a lot more lines. But removed them to find the error. In forst Post you see the orginal Trigger.. Anyhow. Did the Trigger in PHP instead. Quote Link to comment https://forums.phpfreaks.com/topic/216605-cant-create-trigger-whats-wrong-in-my-code/#findComment-1129240 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.