MySQL触发器在插入具有新的自动增量ID的更新列之前 [英] MySQL trigger before insert update column with new auto-increment id
本文介绍了MySQL触发器在插入具有新的自动增量ID的更新列之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用国家代码和新的id
(这是一个自动递增的值)更新表中的列.
I'd like to update a column in my table with the country code and the new id
which is an auto-increment value.
BEGIN
SET new.key = concat(new.countryCode,new.id);
END
countryCode
可以正常工作,但是id
始终为空白.我该如何实现这样的目标? id
来自autoincrement
列.
countryCode
works fine, but the id
is always blank. How can I achieve something like this? The id
comes from an autoincrement
column.
我知道它不起作用,因为它是在插入后生成的.那我该怎么做呢?
I know it's not working because it's generated after the insert. So how can I do something like this?
推荐答案
AUTO_INCREMENT
列仅在插入之后设置.
如果您需要访问该值,则只能在AFTER INSERT
触发器中.但是,您不能在AFTER UPDATE
触发器中修改列值...
If you need to access that value, you can only in an AFTER INSERT
trigger. However, you cannot modify a column value in an AFTER UPDATE
trigger...
查看全文