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 7866887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:32:38+00:00 2026-06-03T00:32:38+00:00

In MySQL I used INSERT IGNORE statement to insert rows to table. Because one

  • 0

In MySQL I used INSERT IGNORE statement to insert rows to table. Because one column is UNIQUE, some rows were not inserted (as they already been there). After execution of that statement I noticed that auto increment column has some missing numbers between rows, which later I realized that happened due to rows that was ignored and not added.

Is it possible to setup system to not increase auto increment counter if no row is inserted with IGNORE clause?

  • 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-06-03T00:32:40+00:00Added an answer on June 3, 2026 at 12:32 am

    Quoting from the manual page for INSERT:

    If you use the IGNORE keyword, errors that occur while executing the
    INSERT statement are treated as warnings instead. For example, without
    IGNORE, a row that duplicates an existing UNIQUE index or PRIMARY KEY
    value in the table causes a duplicate-key error and the statement is
    aborted. With IGNORE, the row still is not inserted, but no error is
    issued.

    The INSERT IGNORE syntax is just a way to suppress certain error messages and it’s helpful when you are aware that those errors might happen and/or want to handle them at a later stage. Behind the scenes, you still have a regular insert, except that it fails due to a violated key. MySQL needs the actual row values to make an insert and the AUTO_INCREMENT counter will increment according to regular rules:

    1. The value for the column is NULL.
    2. The value for the column is not set.
    3. The value for the column is greater than the counter.

    So unless you can rethink your logic (e.g., test whether the key values exist before making the insert), the only way to reset the counter is ALTER TABLE:

    ALTER TABLE t2 AUTO_INCREMENT = value;
    

    It is not that gaps should matter anyway. If they do (e.g., you’re generating invoice numbers that need to be correlative), you’re probably using the wrong tool for the job.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following query was successful when I used in mysql INSERT INTO user(`dev_id`,`email`) VALUES('123','456@gmail.com');
Two libraries for Mysql. I've always used _mysql because it's simpler. Can anyone tell
I'm not exactly new to PHP but I haven't used MySQL that much, so
I am trying to insert a mysql query itself into a table field(Executing a
How can I import a mysql database dump file (contains insert and create table
In mysql, how do I get the primary key used for an insert operation,
I have an insert query for MySQL that looks like this: INSERT INTO table
The MySQL Syntax Used INSERT INTO friend_locations (user_id, lat, long) VALUES ('82441', '28.665899', '-81.359756')
Mysql table (migration_terms) fields are as follows oldterm count newterm seed I used the
Just experimenting I've used this query on MySQL: insert into table_name (text_col) values (1919191919191919191919191...91919191)

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.