陈嘉雨 陈嘉雨 -4 years ago 157
MySQL Question

the error with trigger in MySQL 5.1.63-community

I write a trigger in MySQL 5.1.63-community , it's always note:#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 6 ,but I run the code at navicat for mysql ,it's ok.

code here:

CREATE TRIGGER trig_sign
AFTER insert on students
for each row
Begin
INSERT INTO sign_in(num,uptime,flag,sid)
values(null,now(),false,NEW.sid);
end;

Answer Source

If the trigger body contains only one statement you don't need to use BEGIN and END:

CREATE TRIGGER trig_sign AFTER INSERT on students FOR EACH ROW
    INSERT INTO sign_in(num,uptime,flag,sid) VALUES(null,now(),false,NEW.sid);

For multiple statement triggers you need to switch the delimiter:

DELIMITER //

CREATE TRIGGER trig_sign 
AFTER INSERT on students
FOR EACH ROW
BEGIN
    INSERT INTO sign_in(num,uptime,flag,sid)
        VALUES(null,now(),false,NEW.sid);
    -- more statements
END //

DELIMITER ;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download