本文介绍了在多行插入中使用LAST_INSERT_ID()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在插入查询中使用LAST_INSERT_ID()?
Is it possible to use LAST_INSERT_ID() within an insert query?
INSERT INTO mytable (col1, col2) VALUES ('val1', null), ('val2', LAST_INSERT_ID())
尝试上面的LAST_INSERT_ID()返回0,只是看看我是否可以组合查询.
Trying the above LAST_INSERT_ID() returns 0, Just seeing if i can combine the query.
推荐答案
从我的发现来看,它是无效的,因为LAST_INSERT_ID在整个语句完成之前没有值.
From what i found it won't work as LAST_INSERT_ID doesn't have a value until the whole statement has finished.
这篇关于在多行插入中使用LAST_INSERT_ID()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!