MySQL SELECT LAST_INSERT_ID() 作为复合键。 是否可以?
我可以获得 MySQL 中复合键的 LAST INSERT ID() 吗?
Can I get the LAST INSERT ID() for a compound key in MySQL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。 一个表中不能有多个自增字段。
LAST_INSERT_ID()
仅返回声明为AUTO_INCRMENT
的列的值。 没有函数可以返回不是由系统生成的复合主键中的值。 您应该已经知道该值,因为您刚刚在INSERT
语句中给出了它。 棘手的情况是当触发器或某些东西覆盖该值时。Yes. You can't have multiple auto-increment fields in a single table.
LAST_INSERT_ID()
returns the value only for a column declaredAUTO_INCREMENT
. There's no function to return the value in a compound primary key that wasn't generated by the system. You ought to know that value already, since you just gave it in anINSERT
statement. The tricky case would be when a trigger or something overrides the value.