简体   繁体   中英

Syntax error in MySQL delete trigger

Help with MySQL trigger? I am trying to create an on delete insert trigger in my SQL... I have so far:

CREATE
[DEFINER = {user| CURRENT_USER }]
TRIGGER ProjectDoneTrigger After Delete
ON Project FOR EACH ROW insert into projectover values(old.projectID,old.name,
old.Department,old.MaxHours, old.StartDate,
old.EndDate);

However MySQL reports a syntax error on the first [ on line 2... what is the correct way to do that line?

Read in detail the MySQL Reference Manual, especially the Typographical and Syntax Conventions section (starting from line In syntax descriptions, square brackets (“[” and “]”) indicate optional words or clauses. ). Check in the Reference Manual, which parts from the second line of your code you really need. You could change your code to (assuming you want the TRIGGER statement defaults):

CREATE TRIGGER ProjectDoneTrigger AFTER DELETE ON Project 
FOR EACH ROW
INSERT INTO projectover 
VALUES (old.projectID,old.name, old.Department,old.MaxHours, 
old.StartDate, old.EndDate);

More information about the TRIGGER syntax, check out the Using Triggers section of the Reference Manual.

Brackets indicate that whatever is contained inside them is optional - whatever is in there is not required for the command to function but might be something you want to use, depending on what you're using the command for. Brackets are never to be taken literally so never include them when executing a command.

The DEFINER part is only useful if you want to specify a MySQL account to be used when checking access privileges at trigger activation time. I'd say it's an advanced topic and should be left out unless you know that you need it.

If want a description of what DEFINER does in more detail, it's available in the CREATE TRIGGER manual .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM