MYSQL:在INSERT期间获取ID [英] MYSQL: Get the ID during INSERT
问题描述
大家好,
我不知道这是否可行。我的猜测是不是我会试一试。
是否可以获取我正在插入的当前行的ID(自动编号)。
我知道你可以使用LAST_INSERT_ID()方法,但只有在INSERT之后这样做才有效。我想要实现的是这样的事情
< blockquote class =post_quotes>
大家好,
我不知道这是否可行。我的猜测是不是我会试一试。
是否可以获取我正在插入的当前行的ID(自动编号)。
我知道你可以使用LAST_INSERT_ID()方法,但只有在INSERT之后这样做才有效。我想要实现的是这样的事情
展开 | 选择 | Wrap | 行号
如果它是一个自动增量字段,那么我猜你可以使用max(id)+1 ......
问候,
RP
感谢您的回复。不幸的是,这不起作用,因为go get MAX(id)我需要在当前更新的表上使用SELECT查询。这在MYSQL中是不允许的。我试图使用的查询是:
展开 | 选择 | Wrap < span class =codeDivider> | 行号
MAX()功能不能用于您的目的!如果你想要的只是在插入之前知道下一个auto_increment值,你可以通过发出这个命令得到下一个id展开 | 选择 | Wrap | 行号
Hi guys,
I don''t know if this is possible. My guess is it isn''t but I''ll give it a try.
Is it possible to get the ID (autonumber) of the current row I''m inserting.
I know you can use LAST_INSERT_ID() method but it only works if I do this after the INSERT. What I''d like to achieve is something like this
Expand|Select|Wrap|Line Numbers解决方案Hi guys,
I don''t know if this is possible. My guess is it isn''t but I''ll give it a try.
Is it possible to get the ID (autonumber) of the current row I''m inserting.
I know you can use LAST_INSERT_ID() method but it only works if I do this after the INSERT. What I''d like to achieve is something like this
Expand|Select|Wrap|Line Numbers
Hi,
If it is a auto increment field then i guess you can use max(id)+1 ...
Regards,
RPThanks for the response. Unfortunately this will not work since go get MAX(id) I need to use a SELECT query on the table being currently updated. This is not allowed in MYSQL. The query I''ve tried to use is:
Expand|Select|Wrap|Line Numbers
The MAX() function cannot be used for your purpose! When all you want is to known the next auto_increment value before inserting, you can get the next id by issuing this commandExpand|Select|Wrap|Line Numbers
这篇关于MYSQL:在INSERT期间获取ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文登录 关闭
扫码关注1秒登录发送“验证码”获取 | 15天全站免登陆