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

  • Home
  • SEARCH
  • 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 6828761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:25:15+00:00 2026-05-26T22:25:15+00:00

In my MySQL table I’ve created an ID column which I’m hoping to auto-increment

  • 0

In my MySQL table I’ve created an ID column which I’m hoping to auto-increment in order for it to be the primary key.

I’ve created my table:

CREATE TABLE `test` (
        `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
        `name` VARCHAR( 50 ) NOT NULL ,
        `date_modified` DATETIME NOT NULL ,
    UNIQUE (
        `name`
    )
) TYPE = INNODB;

then Inserted my records:

INSERT INTO `test` ( `id` , `name` , `date_modified` ) 
VALUES (
    NULL , 'TIM', '2011-11-16 12:36:30'
), (
    NULL , 'FRED', '2011-11-16 12:36:30'
);

I’m expecting that my ID’s for the above are 1 and 2 (respectively). And so far this is true.
However when I do something like this:

insert into test (name) values ('FRED') 
on duplicate key update date_modified=now();

then insert a new record, I’m expecting it to be 3, however now I’m shown an ID of 4; skipping the place spot for 3.

Normally this wouldn’t be an issue but I’m using millions of records which have thousands of updates every day.. and I don’t really want to even have to think about running out of ID’s simply because I’m skipping a ton of numbers..

Anyclue to why this is happening?

MySQL version: 5.1.44

Thank you

  • 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-26T22:25:16+00:00Added an answer on May 26, 2026 at 10:25 pm

    Is it possible to change your key to unsigned bigint – 18,446,744,073,709,551,615 is a lot of records – thus delaying the running out of ID’s

    Found this in mysql manual http://dev.mysql.com/doc/refman/5.1/en/example-auto-increment.html

    Use a large enough integer data type for the AUTO_INCREMENT column to hold the
    maximum sequence value you will need. When the column reaches the upper limit of
    the data type, the next attempt to generate a sequence number fails. For example,
    if you use TINYINT, the maximum permissible sequence number is 127. 
    For TINYINT UNSIGNED, the maximum is 255.
    

    More reading here http://dev.mysql.com/doc/refman/5.6/en/information-functions.html#function_last-insert-id it could be inferred that the insert to a transactional table is a rollback so the manual says “LAST_INSERT_ID() is not restored to that before the transaction”

    What about for a possible solution to use a table to generate the ID’s and then insert into your main table as the PK using LAST_INSERT_ID();

    From the manual:

    Create a table to hold the sequence counter and initialize it:
    
    mysql> CREATE TABLE sequence (id INT NOT NULL);
    mysql> INSERT INTO sequence VALUES (0);
    
    Use the table to generate sequence numbers like this:
    
    mysql> UPDATE sequence SET id=LAST_INSERT_ID(id+1);
    mysql> SELECT LAST_INSERT_ID();
    
    The UPDATE statement increments the sequence counter and causes the next call to
    LAST_INSERT_ID() to return the updated value. The SELECT statement retrieves that
    value. The mysql_insert_id() C API function can also be used to get the value. 
    See Section 20.9.3.37, “mysql_insert_id()”.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

MySQL table with couple of fields: id - PRIMARY KEY url - CHAR(255) .
I've a MySQL table folders: CREATE TABLE IF NOT EXISTS `folders` ( `id` int(11)
I have a MySQL table consisting of: CREATE TABLE `url_list` ( `id` int(10) unsigned
I have a mySQL table which contains rows based on payments. Each row contains
So I have a MySQL table with a series of dates which formatted as
Let t be a mysql table and n be an integer column in it.
My mysql table has a createdOn column with filedtype 'timestamp' in the format of
Hi I have a mysql table having the following fields A INT, B INT,
I have a MySQL table which contains the following two fields (There are others,
I have a MySQL table with many numeric columns (some INT, some FLOAT). I

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.