gpt4 book ai didi

mysql - 错误 #1054 - 'NEW 中的未知列 'program_id'

转载 作者:行者123 更新时间:2023-11-29 09:39:15 24 4
gpt4 key购买 nike

努力实现-

每当在 tb_jobs 上进行任何插入时,我都会尝试更新 tb_sites_3 中的 color_status(3 将根据我们从 tb_tickets 获得的 program_id 进行动态调整)。

错误

创建触发器时出现以下错误错误 #1054 - “NEW”中的未知列“program_id”

tb_tickets tb_tickets

tb_jobs

enter image description here

tb_sites_3

enter image description here

DELIMITER //
CREATE TRIGGER trig_job_color
BEFORE INSERT ON `tb_jobs`
FOR EACH ROW
BEGIN
SET NEW.program_id = (Select program_id from tb_tickets
where tb_tickets.job_id = NEW.job_id);
SET NEW.status = (Select status from tb_tickets
where tb_tickets.job_id = NEW.job_id);

CASE NEW.program_id
WHEN 1 THEN
UPDATE tb_sites_1
SET color_status = NEW.status
WHERE site_id = NEW.site_id;
WHEN 2 THEN
UPDATE tb_sites_2
SET color_status = NEW.status
WHERE site_id = NEW.site_id;
WHEN 3 THEN
UPDATE tb_sites_3
SET color_status = NEW.status
WHERE site_id = NEW.site_id;
END CASE;
END //
DELIMITER ;

表定义

tb_tickets

CREATE TABLE `tb_tickets` (
`id` int(15) NOT NULL,
`ticket_id` int(15) NOT NULL,
`job_id` int(11) NOT NULL,
`site_id` varchar(200) NOT NULL,
`program_id` int(11) NOT NULL,
`status` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

tb_jobs

CREATE TABLE `tb_jobs` (
`job_id` int(11) NOT NULL AUTO_INCREMENT,
`job_creation` date DEFAULT NULL,
PRIMARY KEY (`job_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1

tb_sites_3

CREATE TABLE `tb_sites_3` (
`id` int(15) NOT NULL AUTO_INCREMENT,
`color_status` int(15) NOT NULL,
`site_id` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1

最佳答案

插入tb_jobs后创建触发器trig_job_color 对于每一行开始SET @program_id =(从tb_tickets中选择program_id 其中 tb_tickets.job_id = NEW.job_id);

SET @newstatus = (Select status from tb_tickets
where tb_tickets.job_id = NEW.job_id);
SET @newsite_id = (Select site_id from tb_tickets
where tb_tickets.job_id = NEW.job_id);

CASE @program_id
WHEN 1 THEN
UPDATE tb_sites_3
SET tb_sites_3.color_status = @newstatus
WHERE tb_sites_3.site_id = @newsite_id;
WHEN 2 THEN
UPDATE tb_sites_3
SET tb_sites_3.color_status = @newstatus
WHERE tb_sites_3.site_id = @newsite_id;
WHEN 3 THEN
UPDATE tb_sites_3
SET tb_sites_3.color_status = @newstatus
WHERE tb_sites_3.site_id = @newsite_id;
END CASE;
END

关于mysql - 错误 #1054 - 'NEW 中的未知列 'program_id',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56964816/

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