gpt4 book ai didi

mysql - 当该类别的任务插入到任务表中时,我想增加该类别的任务计数

转载 作者:行者123 更新时间:2023-11-29 22:07:17 25 4
gpt4 key购买 nike

CREATE TRIGGER tr_task_forinsert
AFTER INSERT ON task for each row
BEGIN
SET @count = (select countoftask from category where catid = NEW.catid and userid=NEW.userid);

UPDATE category
SET countoftask = @count+1
WHERE catid=NEW.catid and userid=NEW.userid;
END

哪里出错了?

任务表

+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| taskid | int(11) | NO | PRI | NULL | auto_increment |
| taskname | varchar(255) | YES | | NULL | |
| catid | int(11) | YES | MUL | NULL | |
| userid | int(11) | YES | MUL | NULL | |
| taskdate | date | YES | | NULL | |
| tasktime | varchar(255) | YES | | NULL | |
+----------+--------------+------+-----+---------+----------------+

类别表

+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| catid | int(11) | NO | PRI | NULL | auto_increment |
| catname | varchar(255) | YES | | NULL | |
| userid | int(11) | NO | PRI | 0 | |
| countoftask | int(11) | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+

最佳答案

您不需要将值提取到变量中,但这不会导致错误。这是一个更简单的形式:

DELIMITER $$
CREATE TRIGGER tr_task_forinsert
AFTER INSERT ON task for each row
BEGIN
UPDATE category
SET countoftask = countoftask + 1
WHERE catid = NEW.catid and userid = NEW.userid;
END;
$$
DELIMITER ;

您的问题可能只是分隔符。

关于mysql - 当该类别的任务插入到任务表中时,我想增加该类别的任务计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32037181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com