Jump to content

Data-Type for ID?


doubledee

Recommended Posts

How hard is it to change the data-type for your Primary Key if you outgrow it?

 

I am creating an error table and was going to use MediumInt since I figure that if I log more than 16 million Errors then I either have code issues or a honking big site?!  :D

 

If I ever need to upgrade to Int would it be a big deal?

 

Thanks,

 

 

Debbie

 

P.S.  Why do I have to set a Length for the data-type like this MediumInt( 8 ) in phpMyAdmin??

 

I thought all MediumInt's were 8 characters wide?

 

 

Link to comment
Share on other sites

Upgrading isnt an issue at all as your only extending the amount of possibilities available. At byte level your literally adding more bytes, that's all. All the values in a mediumint type are available in an int type.

 

Regarding the length, there will be a maximum value which can be set in a mediumint type and it will be X characters long. You can shorten the maximum length by setting a value but mediumint will have a limit itself, can't remember what the limits of any of the integers types are at the minute but you can look it up.

 

 

Link to comment
Share on other sites

I usually just start out all my ID's with INT UNSIGNED which allows up to 2 billion. Chances are no table in anything I do will ever hit that, but if by some miracle one did the type could just be upped to bigint without much trouble.

 

 

 

P.S.  Why do I have to set a Length for the data-type like this MediumInt( 8 ) in phpMyAdmin??

 

I don't really know about how phpMyAdmin works, but for numeric types the length parameter does not affect how much space is used or how many digits you can store.  It's used only for display purposes when you SELECT that number, and doesn't really do much unless you use the ZEROFILL option to pad zeros.

 

Link to comment
Share on other sites

P.S.  Why do I have to set a Length for the data-type like this MediumInt( 8 ) in phpMyAdmin??

 

I don't really know about how phpMyAdmin works, but for numeric types the length parameter does not affect how much space is used or how many digits you can store.  It's used only for display purposes when you SELECT that number, and doesn't really do much unless you use the ZEROFILL option to pad zeros.

 

Oh, okay.  That makes sense with the ZeroFIll.

 

Thanks!

 

 

Debbie

 

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.