I want to store Zip Code (within United States) in MySQL database. Saving space is a priority. which is better option using VARCHAR - limited to maximum length of 6 digit or using INT or using MEDIUM Int . The Zip code will not be used for any calculation. The Zip code will be used to insert (Once), Updated (if required) and Retrieved - Once (but it can be more than once) .
Which is better option to use here VARCHAR or INT or MEDIUM IN MYSQL ? Please suggest anything else ?
There are a few problems with storing a zip code as a numeric value.
12345-6789
. You cannot store a dash in a numeric datatype.I would store a zip code as a varchar(5)
or varchar(10)
.
As a side note, I am not sure why you would select varchar(6)
, do you have a reason for selecting an unusual length when standard zip codes are 5 or 10 with the extension?