1

I am trying to set up a trigger on a table to copy the contents of a row into another table.

I have the following:

CREATE TRIGGER story_deleted BEFORE DELETE ON stories 
  FOR EACH ROW BEGIN
    INSERT INTO stories_backup SET story_id = OLD.story_id;  
  END;

This returns the following error though:

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 3

I can't work out where I'm going wrong with this. Any ideas?

8
  • The code is correct. How are you executing this query, in phpmyadmin? Commented Apr 13, 2012 at 12:45
  • As a workaround - try to remove BEGIN and END keywords. Commented Apr 13, 2012 at 12:46
  • trying to execute in phpMyAdmin... Commented Apr 13, 2012 at 12:47
  • It can be a problem with source objects and delimiters. Try workaround. Commented Apr 13, 2012 at 12:49
  • @Devart This returns the following: 1419 - You do not have the SUPER privilege and binary logging is enabled Commented Apr 13, 2012 at 12:50

1 Answer 1

2

Try changing the delimiter

DELIMITER $$

CREATE TRIGGER story_deleted BEFORE DELETE ON stories  
  FOR EACH ROW
  BEGIN 
    INSERT INTO stories_backup SET story_id = OLD.story_id;   
  END $$

DELIMITER ;

and as far as your privileges go, run this query

SHOW GRANTS;

If SUPER is not there, you could

  • request your DBA to add that privilege for you
  • have your DBA create the trigger for you
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.