[KLUG Programming] questions on picking data types
Jamie McCarthy
jamie at mccarthy.vg
Wed Jul 14 17:07:33 EDT 2004
ENUM for gender makes sense.
For SSN, three fields feels wrong to me. I imagine the only
operation you'll be doing on this field, apart from reading and
writing it, is searching on the whole thing. Will you ever need
to retrieve all SSNs with "45" as the middle 2 digits?
If not, then it probably makes more sense to just store the
9-digit SSN as an INT. That way when you need to retrieve a row
when you know the whole SSN, it's one index lookup instead of
three. A single INT takes fewer bytes than the three-field idea
too, though that's a very, very small difference.
The only gotcha with doing all 9 digits in one INT is that if you
need to parse it with hyphens, you'll have to do that in your
input and/or output code. But that's where you should be doing
that anyway. Far as I'm concerned, all that cruft, adding hyphens
for the most common representation of SSN, or parens or hyphens or
periods or whatever to the 14 most common ways to write a phone
number, is all I/O handling. You shouldn't design your DB schema
based on whether "(123) 456-7890" or "123.456.7890" is preferred
this week or in this country, and the same goes for "123-45-6789".
--
Jamie McCarthy
http://mccarthy.vg/
jamie at mccarthy.vg
More information about the Programming
mailing list