如何获取在mysql INSERTed行的ID?

编程入门 行业动态 更新时间:2024-10-09 17:25:06
本文介绍了如何获取在mysql INSERTed行的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用此命令将一些单词插入到两列表中...

INSERT IGNORE INTO terms )VALUES('word1'),('word2'),('word3')

  • 如何获取每个字被插入的行的ID(主键)。我的意思是在INSERT后返回一个像55,56,57的值。 MySQL有这样的响应吗?

  • 术语列是UNIQUE。如果某个术语已存在,则不会插入它。可以返回此重复的引用(即,术语存在的行的ID)。

  • 解决方案 div>

  • 您通过 SELECT LAST_INSERT_ID(); 或通过框架/ MySQL库(无论什么语言)调用 mysql_insert_id() 。 p>

  • 这不会工作。您必须在插入后查询ID。

  • I am INSERTing some words into a two-column table with this command...

    INSERT IGNORE INTO terms (term) VALUES ('word1'), ('word2'), ('word3')

  • How can I get the ID (Primary Key) of the row in which each word is INSERTed. I mean returning a value like "55,56,57" after INSERT. Does MySQL have such a response?

  • The term column is UNIQUE. If a term already exists, it will not INSERT it. Is it possible to return the reference for this duplication (i.e. the ID of the row in which the term exists). A response like "55,12,56".

  • 解决方案

  • You get it via SELECT LAST_INSERT_ID(); or via having your framework/MySQL library (in whatever language) call mysql_insert_id().

  • That won't work. There you have to query the IDs after inserting.

  • 更多推荐

    如何获取在mysql INSERTed行的ID?

    本文发布于:2023-11-22 00:30:57,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1615279.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:mysql   INSERTed   ID

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!