I want to store Zip Code (within United States) in MySQL database. Saving space is a priority. which is better option using VARCHAR - limited
I usually use MEDIUMINT(5) ZEROFILL
for 5 digit zip codes. This preserves any leading 0
s and it only uses 3 bytes where a VARCHAR(5)
would use 6. This assumes that you don't need the extended zip codes, which have a dash and 4 extra numbers. If you were to decide to use a textual type, I would use CHAR(5)
instead of VARCHAR(5)
since it is better if the data is always 5 characters long.