gpt4 book ai didi

MySQL触发器在删除操作之前插入另一个表

转载 作者:行者123 更新时间:2023-11-29 19:01:31 25 4
gpt4 key购买 nike

我写过类似的东西,但它不起作用。怎么办?

mysql> create trigger deleteStudentTrigger
-> before delete on tblStudent for each row
-> begin
-> insert into tblDeletedStudents select * from tblStudent where StudentId = new.StudentId;
-> end;$

ERROR 1363 (HY000): There is no NEW row in on DELETE trigger

最佳答案

如错误中所述,没有新行,只有旧行(因为当您删除某些内容时,它不是新的,您知道)所以应该是这样

mysql> create trigger deleteStudentTrigger
-> before delete on tblStudent for each row
-> begin
-> insert into tblDeletedStudents select * from tblStudent where StudentId = old.StudentId;
-> end;$

有关更多信息,请参阅 MySQL 文档

关于MySQL触发器在删除操作之前插入另一个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43841751/

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