简体   繁体   English

MySQL在插入的值数组中插入ID

[英]Mysql inserted id in the insert's value array

so I'm storing order in my table like this: 因此我将订单存储在表中,如下所示:

ID, NAME, ORDER ID,NAME,ORDER

1, name_1, 1000 1,名称_1、1000

2, name_2, 2000 2,名称_2,2000年

3, name_3, 3000 3,name_3、3000

so basically: ORDER = ID*1000 所以基本上:ORDER = ID * 1000

and what I do is after inserting row into this table like this 而我要做的是像这样在表中插入行后

INSERT INTO table(name) VALUES('name_x');

I update order value in this row like this: 我在此行中更新订单值,如下所示:

UPDATE table SET order = mysql_insert_id()*1000 WHERE id = mysql_insert_id();

Is there any other way to not make this into two statements? 还有其他方法可以不将其分为两个语句吗? Like some magical mysql function ACT_ID() 就像一些神奇的mysql函数ACT_ID()

so it would be like 所以就像

INSERT INTO table(name, order) VALUES('name_x',ACT_ID()*1000);

Thanks in advance for all your responses. 预先感谢您的所有回复。

Yes there is: 就在这里:

INSERT INTO tbl2 (id,text) VALUES(LAST_INSERT_ID(),'text');

See MySQL Docs here 在这里查看MySQL文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM