我使用此命令将一些单词插入到两列表中...
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?
发布评论