我是靠谱客的博主 迷路小懒虫,最近开发中收集的这篇文章主要介绍mysql 触发器更新多张表_条件为真时,如何使用MySQL触发器更新多个表?,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

我正在尝试创建一个触发器来更新带有条件检查的另一个表,但是我一直收到MySQL错误.我的触发器的代码是:

DELIMITER $$

CREATEb

TRIGGER visitor_validation

BEFORE INSERT ON ratingsvisitors

FOR EACH ROW

BEGIN

Set @counts=(SELECT count(*) from ratingsvisitors where visotrid=new.userid AND profileid=New.profileid AND itemid=New.itemid AND likevalidation=New.likevalidation AND likesordislike=New.likesordislike);

SET @ifexists = (SELECT * FROM ratingcounttracks WHERE userid=New.userid AND likedate=New.likevalidation AND countfor=New.likesordislike);

IF (@ifexists = NULL) THEN

INSERT INTO ratingsvisitors(userid, likedate, clickcount,countfor) values (New.userid, New.likevalidation ,'1',New.likesordislike);

ELSE

UPDATE ratingsvisitors SET clickcount=clickcount+1 WHERE userid=New.userid AND likedate=New.likevalidation AND countfor=New.likesordislike;

ENDIF;

END$$

MySQL显示错误:

#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 ‘; END’ at line 12

解决方法:

你可以做这样的事情

DELIMITER $$

CREATE

TRIGGER visitor_validation

BEFORE INSERT ON ratingsvisitors

FOR EACH ROW

BEGIN

Set @counts=(SELECT count(*) from ratingsvisitors where visotrid=new.userid AND

profileid=New.profileid AND itemid=New.itemid AND likevalidation=New.likevalidation AND

likesordislike=New.likesordislike);

IF NOT EXISTS (SELECT * FROM ratingcounttracks WHERE userid=New.userid AND

likedate=New.likevalidation AND countfor=New.likesordislike);

THEN

INSERT INTO ratingsvisitors(userid, likedate, clickcount,countfor) values (New.userid,

New.likevalidation ,'1',New.likesordislike);

ELSE

UPDATE ratingsvisitors SET clickcount=clickcount+1 WHERE userid=New.userid AND

likedate=New.likevalidation AND countfor=New.likesordislike;

ENDIF;

END$$

标签:mysql-error-1064,mysql,triggers

来源: https://codeday.me/bug/20191201/2079431.html

最后

以上就是迷路小懒虫为你收集整理的mysql 触发器更新多张表_条件为真时,如何使用MySQL触发器更新多个表?的全部内容,希望文章能够帮你解决mysql 触发器更新多张表_条件为真时,如何使用MySQL触发器更新多个表?所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部