mysql data type confusion
Posted
by zen
on Stack Overflow
See other posts from Stack Overflow
or by zen
Published on 2010-03-27T17:47:19Z
Indexed on
2010/03/27
17:53 UTC
Read the original article
Hit count: 276
So this is more of a generalized question about MySQLs data types. I'd like to store a 5-digit US zip code (zip_code) properly in this example.
A county has 10 different cities and 5 different zip codes.
city | zip code
-------+----------
city 0 | 33333
city 1 | 11111
city 2 | 22222
city 3 | 33333
city 4 | 44444
city 5 | 55555
city 6 | 33333
city 7 | 33333
city 8 | 44444
city 9 | 22222
I would typically structure a table like this as varchar(50), int(5) and not think twice about it.
(1) If we wanted to ensure that this table had only one of 5 different zip codes we should use the enum data type, right?
Now think of a similar scenario on a much larger scale. In a state, there are five-hundred cities with 418 different zip codes.
(2) Should I store 418 zip codes as an enum data type OR as an int and create another table to reference?
© Stack Overflow or respective owner