Jump to content

MySQL primary key reusal


Al3x

Recommended Posts

For my primary key I have it NOT NULL and AUTO_INCREMENT...let's say it's INT(3) and call it "pkey".

 

This is fine and all...but say I have 20 rows with primary keys 1-20...and I delete #15.  When I add another, it gets the key 21.

 

What happens when I have done this like 300 times?...I may still have 20 rows of data, but eventually my pkey will auto_increment out of values.

 

Is the only way to avoid this by setting the pkey to something like INT(5) or more?  Is there a way to reuse unused primary keys automatically?

Link to comment
Share on other sites

You have a good point roopurt18.

 

Also BPops you are correct.  I just read this in a mysql book I bought:

 

"Integer with a range from -2147483648 to +2147483647.  The number that can be displayed is limited by length.  For example, if length is 4, only numbers from -999 to 9999 can be displayed, even though higher numbers are stored.

 

What does it mean "displayed" though?  Does that mean if I query it in PHP and output it...will it output the entire int?  Or is that considered a display?  I guess I can play around with that one.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.