Jump to content

mysql column type question


s0c0

Recommended Posts

So lets say I have an orders table with an invoice column as the primary key and several other columns.  I'll auto-increment the invoice starting at the number 1 and I don't even anticipate there to be more than 1,000,000 records.  So I set the type to medium int and assign it a value of 6.  What I'm getting at is why is this a better practice than just assigning that column say a type of int with a value of 10?  Is this even a best practice?  Does this even matter?  Please advise.

Link to comment
Share on other sites

Honestly... in the scenario you provided there's not a lot of difference. Originally this stuff mattered and developers needed to be very mindful about disk storage (hard drive space) as it was very precious. Today this stuff is cheap so there's not much of a reason to not make it the max in a situation like this.

 

If you had some field that you knew would never exceed X due to some real world constraint or business rule then it might not hurt to use the smaller datatype, but again there is very little noticeable difference.

 

When it does matter is with text vs char vs varchar datatypes. You should read up on how these work so you know which is best. The easy route is to choose text, however there are some definite drawbacks as text fields can not be indexed, etc.

 

I hope this helps and gets you in the right direction.

Link to comment
Share on other sites

Like above, i think that in that specific situation, it doenst really matter. Make it bigger, just so you dont have to think about it later.

Having perfect sizes for column types, comes handy in big projects/db.

 

But, dont exagerate, like i seen, to give bigint(30) to something that wont ever pass, ever, 6 digits!

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.