获取MySQL触发器错误

时间:2014-04-10 07:12:32

标签: mysql sql stored-procedures syntax-error

我在WordPress数据库中编写了一个MySQL触发器&它给出了一个错误。我的触发器代码如下:

CREATE 
  [DEFINER = { user | CURRENT_USER }]
  TRIGGER up_trig AFTER INSERT ON `wp_postmeta` 
  FOR EACH ROW
  BEGIN
    DECLARE `pan_id` INT
    "SELECT DISTINCT (`meta_value`) INTO `pan_id`
     FROM `wp_postmeta`
     WHERE `meta_key` = 'panchayat_id' 
     AND `meta_value` = NEW.(SELECT DISTINCT meta_value 
                             FROM wp_postmeta 
                             WHERE meta_key = panchayat_id)"

    IF `pan_id` != 'NULL'  THEN
       UPDATE `wp_panchayatpost`
       SET post_count = post_count+1
       WHERE 'panchayat_id' = 'pan_id';
    END IF;
END;

它提供了以下错误消息:

  

错误

     

SQL查询:文档

     

CREATE [DEFINER = {user | CURRENT_USER}] TRIGGER up_trig插入后   ON wp_postmeta FOR EACH ROW BEGIN DECLARE pan_id INT" SELECT   DISTINCT(meta_value)INTO pan_id FROM wp_postmeta WHERE   meta_key =' panchayat_id' AND meta_value = NEW。(选择DISTINCT   meta_value FROM wp_postmeta WHERE meta_key = panchayat_id)"如果   pan_id!=' NULL'那么更新wp_panchayatpost SET post_count =   post_count +1 WHERE' panchayat_id' =' pan_id';

MySQL说:文档

  

#1064 - 您的SQL语法出错;检查与MySQL服务器版本对应的手册,以获得正确的语法   靠近' [DEFINER = {user | CURRENT_USER}] TRIGGER up_trig                   插入后#39;在第2行

1 个答案:

答案 0 :(得分:0)

只需删除[DEFINER = { user | CURRENT_USER }]即可。当您想要定义触发器所有者用户的类型时,它是必需的。或者将其替换为DEFINER=root(或您用于连接的任何其他用户名)。