Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6210901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:14:36+00:00 2026-05-24T06:14:36+00:00

I think the answer to my question is obvious but since I could not

  • 0

I think the answer to my question is obvious but since I could not find any documentation to support it, I thought it’s worth asking. At least for the record.

As we all know AUTO_INCREMENT fields are incremented each time an INSERT statement is executed. And its value can be retrieved by LAST_INSERT_ID() function. It is also mentioned in MySQL’s Manual that with multiple-row inserts, LAST_INSERT_ID() will return the first ID of the inserted rows. Which I think is a good idea (really useful).

So here goes my question:

Can I assume in an INSERT IGNORE INTO statement with multiple-rows, the inserted IDs of an AUTO_INCREMENT field will always be sequential? Keep in mind that due to IGNORE modifier and the multi-user nature of MySQL server, different scenarios might happen.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:14:37+00:00Added an answer on May 24, 2026 at 6:14 am

    No you can not assume that. One scenario where ID’s would not be sequential is in replicated multi-master setup. If for example two servers exist in such setup, one will only generate even auto IDs, and the other only odd IDs (keep in mind it’s just an example).

    However if your setup is not something like that, then yes. At least in InnoDB inserts are atomic and are queued when targetting same table, so ID’s from two different INSERT’s will not interlace. (it’s not documented though, so relying on it is… a bit risky)


    How I tested IGNORE INSERT ID generation:

    mysql> CREATE TABLE  `ignoreinsert` (
        ->   `ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
        ->   `uq` int(10) unsigned NOT NULL,
        ->   PRIMARY KEY (`ID`),
        ->   UNIQUE KEY `uq` (`uq`)
        -> ) ENGINE=InnoDB;
    Query OK, 0 rows affected (0.19 sec)
    
    mysql> INSERT INTO ignoreinsert VALUES (null,1),(null,2);
    Query OK, 2 rows affected (0.10 sec)
    Records: 2  Duplicates: 0  Warnings: 0
    
    mysql> SELECT * FROM ignoreinsert;
    +----+----+
    | ID | uq |
    +----+----+
    |  1 |  1 |
    |  2 |  2 |
    +----+----+
    2 rows in set (0.00 sec)
    
    mysql> INSERT IGNORE INTO ignoreinsert VALUES (null,3),(null,1),(null,4),(null,2),(null,5);
    Query OK, 3 rows affected (0.08 sec)
    Records: 5  Duplicates: 2  Warnings: 0
    
    mysql> SELECT * FROM ignoreinsert;
    +----+----+
    | ID | uq |
    +----+----+
    |  1 |  1 |
    |  2 |  2 |
    |  3 |  3 |
    |  4 |  4 |
    |  5 |  5 |
    +----+----+
    5 rows in set (0.00 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think this is a simple question, but I can not find the answer
I think its a rather simple question but I couldn't really find an answer
I think answer on my question is NO. But still, I'm wondering is it
I think the answer to this is no going in, but I could use
I think I already know the answer to this but thought I would ask
It could very well be that the answer to this question is an obvious
This question may be easy and the answer obvious, but I can't seem to
Maybe the answer is so obvious, I'm not seeing it, but I have a
I am sure there is a very simple answer to this question, I think
[see later answer for more] I think this is just a simple rails question,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.