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?

4

1 回答 1

2

尝试更改分隔符

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 ;

就您的权限而言,运行此查询

SHOW GRANTS;

如果 SUPER 不存在,你可以

  • 请求您的 DBA 为您添加该权限
  • 让您的 DBA 为您创建触发器
于 2012-04-13T18:17:38.253 回答