16

This MySQL script installs multiple triggers.

It works on one machine running MySQL 5.0.51b-community. On another machine running MySQL 14.12 Distrib 5.0.45, for redhat-linux-gnu (i386) it fails, with this error message, which seems to be related to the DELIMITER // ... // DELIMITER; syntax :

ERROR 1064 (42000) at line 272: 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 'DELIMITER; DROP TRIGGER IF EXISTS trigger_name; DELIMITER' at line 1

The script syntax (summarised) is:

DROP TRIGGER IF EXISTS trigger_name;
DELIMITER //
CREATE TRIGGER trigger_name BEFORE UPDATE ON table
FOR EACH ROW BEGIN
  -- Trigger logic goes here
END //
DELIMITER;

-- More trigger drop/create statements follow

What is wrong with the script, and how can I correct it?

Sophia
  • 5,643
  • 9
  • 38
  • 43

7 Answers7

26

Try

DELIMITER ;

not

DELIMITER;

You're actually specifying ; as an argument to the DELIMITER command, so not having the space there may be confusing it.

chaos
  • 122,029
  • 33
  • 303
  • 309
4

You need a space between 'DELIMITER' and ';'

DELIMITER ;
# not:
DELIMITER;
too much php
  • 88,666
  • 34
  • 128
  • 138
3

Just as an add-on, for someone else:

The delimiter is required to enable the entire definition to be passed to the server as a single statement.

Orson
  • 14,981
  • 11
  • 56
  • 70
1

In the version of MySql I use the same error occurs when using the delimiter command, but this version handles the delimiter ";" for statements and delimiter "|" for stored procedures and functions, which i think solves the problem; try this:

DROP TRIGGER IF EXISTS trigger_name;

CREATE TRIGGER trigger_name BEFORE UPDATE ON table FOR EACH ROW BEGIN -- Trigger logic goes here END |

-- other statements or functions here

fedorqui
  • 275,237
  • 103
  • 548
  • 598
lxblanco
  • 11
  • 1
1

Try the below.

I am sure it should solve the purpose.

DELIMITER +
CREATE TRIGGER STUDENT_INSERT_TRIGGER BEFORE INSERT ON FSL_CONNECTIONS 
FOR EACH ROW BEGIN 
INSERT INTO STUDENT_AUDIT 
SET STUDENT_ID = NEW.STUDENT_ID, 
MAC_ADDRESS = NEW.MAC_ADDRESS,
IPADDRESS = NEW.IPADDRESS, 
EMAIL_ID = NEW.EMAIL_ID , 
START_TIME=NEW.START_TIME, 
END_TIME=NEW.END_TIME, 
STATUS=NEW.STATUS; 
END; +

From the above when we use a DELIMITER. It should be in the form of

DELIMITER +
--
BLOCK OF SQL WHATEVER YOU WANT TO MENTION
--
+
j0k
  • 22,600
  • 28
  • 79
  • 90
user438441
  • 11
  • 1
0

Hmm I'm having similar problems. I do a mysqldump from Debian Lenny running 5.0.51 and try importing to OpenSolaris running 5.0 and get the same error. And I have DELIMITER ;

Version conflict?

  • It seemed to be related to versions for us, one version worked with no semicolon, another worked with just a semicolon, and another required a semicolon and no space. – Sophia Sep 03 '09 at 03:04
0

DELIMITER // CREATE TRIGGER age_verified BEFORE INSERT ON customers FOR EACH ROW IF new.age<0 THEN SET new.age=0 END IF;//

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 06 '23 at 09:41