嗨,我正在尝试学习 mysql,但是,在我定义了一个触发器后,该触发器应该在对表中的列进行更新操作后工作,它不能正常工作。每当我更新此列时,它应该立即删除一行。(此列的类型是 DATE 并且它在开头声明为 NULL)。这是我的表结构
Create Table Projects (
pro_ID INT NOT NULL,
pro_Name VARCHAR(150) NOT NULL,
comp_date_info DATE DEFAULT NULL,
PRIMARY KEY(pro_ID)
);
我尝试添加一个带有存储过程的元组
DELIMITER //
CREATE PROCEDURE insert_into_Projects ( IN projectID INT, IN projectName VARCHAR(50) )
BEGIN
INSERT INTO homework.Projects values (projectID, projectName,NULL);
END //
DELIMITER ;
这是在 Projects Table 中添加新元组的调用语句
call insert_into_Projects(111,'Project Mayhem');
到目前为止,你可以意识到我有一个像
pro_ID pro_Name comp_date_info
1) 111 Project Mayhem NULL
这是触发器的实现
DELIMITER //
CREATE TRIGGER after_Projects_update
AFTER UPDATE ON homework.Projects
FOR EACH ROW
BEGIN
delete from homework.Projects
where comp_date_info != NULL;
END //
DELIMITER ;
最后,每当我将此元组的 comp_date_info 更新为适当的日期值触发器时,我都希望将其删除。
update homework.Projects
set comp_date_info = '1989-04-05'
where pro_ID = 113;
但我面临一个错误,上面写着
Error Code: 1442. Can't update table 'Projects' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
如果您能提供帮助,我将不胜感激,顺便感谢您的回复。