s0c0 Posted October 26, 2007 Share Posted October 26, 2007 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. Quote Link to comment Share on other sites More sharing options...
dbo Posted October 27, 2007 Share Posted October 27, 2007 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. Quote Link to comment Share on other sites More sharing options...
Stopofeger Posted November 3, 2007 Share Posted November 3, 2007 I wonder why you want to save this small space. a 11 digit number will take only few bytes more. Now a days hard disk doesn't matter at all. So, why take risk to save these useless space? Quote Link to comment Share on other sites More sharing options...
Gath Posted November 3, 2007 Share Posted November 3, 2007 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.