将自动增量值复制到插入时的另一列? [英] Copy autoincrement value to another column on insert?
问题描述
基本上,我有一个表来对产品进行版本控制,
Basically I have a table that versions products,
所以它有两个感兴趣的列,id | product_id
so it has two columns of interest, id | product_id
id
是autoincrement
列,
product_id
只是一个int
id
is an autoincrement
column,
product_id
is just an int
首次创建产品时,product_id
来自id
,
编辑产品时,我们将复制该行,因此product_id
相同,但ID不同.因此,当我们第一次创建产品时,我们会进行两个查询,
When a product is first created the product_id
comes from the id
,
When the product is edited we duplicate the row, so the product_id
is the same, but the id is different. so when we first create the product we do two queries,
先插入,然后update table whatever set product_id = id where id = {the insert id}
这行得通,但是我想知道是否可以在一个查询中做到这一点?
This works, but I am wondering if there is a way to do it in one query?
请注意,我们仅具有插入,更新,删除的权限.没有触发器或存储过程.
Note we only have access to insert, update, delete. no triggers or stored procedures.
推荐答案
使用 查看全文