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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:14:43+00:00 2026-05-14T19:14:43+00:00

So yesterday we had a table that has an auto_increment PK for a smallint

  • 0

So yesterday we had a table that has an auto_increment PK for a smallint that reached its maximum. We had to alter the table on an emergency basis, which is definitely not how we like to roll.

Is there an easy way to report on how close each auto_increment field that we use is to its maximum? The best way I can think of is to do a SHOW CREATE TABLE statement, parse out the size of the auto-incremented column, then compare that to the AUTO_INCREMENT value for the table.

On the other hand, given that the schema doesn’t change very often, should I store information about the columns’ maximum values and get the current AUTO_INCREMENT with SHOW TABLE STATUS?

  • 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-14T19:14:44+00:00Added an answer on May 14, 2026 at 7:14 pm

    Your question seems perfectly reasonable to me. You should be able to get the current auto-increment values for each table from information_schema. I don’t think the max values for the various int types are available as constants in MySQL, but Roland Bouman demonstrated a simple way to generate them in MySQL:

    In SQL how do I get the maximum value for an integer?

    If you put that data into a table, then you can write a single SQL query to get the current auto-increment status of all of your tables so you can see how close you are to running out of values.

    Here’s a quick-and-dirty example to get you started:

    create temporary table max_int_values
    (
    int_type varchar(10) not null,
    extra varchar(8) not null default '',
    max_value bigint unsigned not null,
    primary key (int_type,max_value),
    key int_type (int_type),
    key max_value (max_value)
    );
    
    insert into max_int_values(int_type,extra,max_value) values ('tinyint','',~0 >> 57);
    insert into max_int_values(int_type,extra,max_value) values ('tinyint','unsigned',~0 >> 56);
    insert into max_int_values(int_type,extra,max_value) values ('smallint','',~0 >> 49);
    insert into max_int_values(int_type,extra,max_value) values ('smallint','unsigned',~0 >> 48);
    insert into max_int_values(int_type,extra,max_value) values ('mediumint','',~0 >> 41);
    insert into max_int_values(int_type,extra,max_value) values ('mediumint','unsigned',~0 >> 40);
    insert into max_int_values(int_type,extra,max_value) values ('int','',~0 >> 33);
    insert into max_int_values(int_type,extra,max_value) values ('int','unsigned',~0 >> 32);
    insert into max_int_values(int_type,extra,max_value) values ('bigint','',~0 >> 1);
    insert into max_int_values(int_type,extra,max_value) values ('bigint','unsigned',~0);
    
    select t.table_Schema,t.table_name,c.column_name,c.column_type,
      t.auto_increment,m.max_value,
      round((t.auto_increment/m.max_value)*100,2) as pct_of_values_used,
      m.max_value - t.auto_increment as values_left
    from information_schema.tables t
      inner join information_schema.columns c 
        on c.table_Schema = t.table_Schema and c.table_name = t.table_name
      inner join max_int_values m 
        on m.int_type = substr(c.column_type,1,length(m.int_type)) 
        and ((m.extra like '%unsigned') = (c.column_type like '%unsigned'))
    where c.extra = 'auto_increment'
    order by pct_of_values_used;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.