insert-id

how do i handle concurrent inserts in mysql table and fetch the correct insert id

拟墨画扇 提交于 2019-11-30 23:13:01
I am using adodb for PHP library. For fetching the id at which the record is inserted I use this function "$db->Insert_ID()" I want to know if there are multiple and simultaneous inserts into the database table, will this method return me the correct inserted id for each record inserted ? The reason I am asking this is because I use this last insert id for further processing of other records and making subsequent entries in the related tables. Is this approach safe enough or am I missing something. Please help me formulate a proper working plan for this so that I can use the last insert id for

MySQL ON DUPLICATE KEY - last insert id?

我的梦境 提交于 2019-11-26 11:35:00
I have the following query: INSERT INTO table (a) VALUES (0) ON DUPLICATE KEY UPDATE a=1 I want the ID of either the insert or the update. Usually I run a second query in order to get this as I believe insert_id() only returns the 'inserted' ID and not the updated ID. Is there a way to INSERT/UPDATE and retrieve the ID of the row without running two queries? fredrik Check this page out: https://web.archive.org/web/20150329004325/https://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html At the bottom of the page they explain how you can make LAST_INSERT_ID meaningful for updates by

MySQL ON DUPLICATE KEY - last insert id?

孤者浪人 提交于 2019-11-26 02:27:53
问题 I have the following query: INSERT INTO table (a) VALUES (0) ON DUPLICATE KEY UPDATE a=1 I want the ID of either the insert or the update. Usually I run a second query in order to get this as I believe insert_id() only returns the \'inserted\' ID and not the updated ID. Is there a way to INSERT/UPDATE and retrieve the ID of the row without running two queries? 回答1: Check this page out: https://web.archive.org/web/20150329004325/https://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html

How to get the insert ID in JDBC?

送分小仙女□ 提交于 2019-11-25 21:43:32
问题 I want to INSERT a record in a database (which is Microsoft SQL Server in my case) using JDBC in Java. At the same time, I want to obtain the insert ID. How can I achieve this using JDBC API? 回答1: If it is an auto generated key, then you can use Statement#getGeneratedKeys() for this. You need to call it on the same Statement as the one being used for the INSERT . You first need to create the statement using Statement.RETURN_GENERATED_KEYS to notify the JDBC driver to return the keys. Here's a