I am running the example from the following webpage:
MySQL :: MySQL 5.0 Reference Manual :: 12.1.11 CREATE TRIGGER Syntax
and the problem is that triggers cannot be defined for some reason:
CREATE DATABASE IF NOT EXISTS triggertest;
USE triggertest;
CREATE TABLE test1(a1 INT);
CREATE TABLE test2(a2 INT);
CREATE TABLE test3(a3 INT NOT NULL AUTO_INCREMENT PRIMARY KEY);
CREATE TABLE test4(
a4 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
b4 INT DEFAULT 0
);
delimiter |
CREATE TRIGGER testref BEFORE INSERT ON test1
FOR EACH ROW BEGIN
INSERT INTO test2 SET a2 = NEW.a1;
DELETE FROM test3 WHERE a3 = NEW.a1;
UPDATE test4 SET b4 = b4 + 1 WHERE a4 = NEW.a1;
END;
|
delimiter ;
and the result is:
Error: 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 | CREATE TRIGGER testref BEFORE INSERT ON test1 FOR EACH ROW BE' at line 1
The database is initially empty, no other tables or triggers. What is the exact problem here and how do I fix it? Thanks in advance.
# mysql -v
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 164
Server version: 5.1.28-rc FreeBSD port: mysql-server-5.1.28_1