Personally (because this is a somewhat subjective question) I'd go with ENUM
. MySQL doesn't support CHECK
constraints, so the ENUM
is the only way to really make sure the value is M
or F
(or m
or f
). To me, that's the most important point.
In addition, the ENUM
should only need one byte of storage space (according to the docs), so it's just as efficient storage-wise as CHAR(1)
or TINYINT
.
I don't understand the TINYINT
approach at all because you end up with queries like this:
SELECT * FROM myTable WHERE gender = 1;
Is 1
male or female? And if it's male, is female 0
? Or is it 2
? Or maybe 16
? You already have to remember a pile of things to write (and maintain) an application; no need to add to that pile.
Addendum 2017-12-01 by Ed Gibbs: Revisiting my answer when I stumbled across it on an unrelated Google search...
The ENUM
approach has merit in use cases with a static, single-dimensional domain of values (e.g., Y/N, To/Cc/Bcc), but it's not valid for gender. My answer was in the nerd context of "how do you limit a column to M or F" and not in the broader context of gender definition.
D Mac's solution is more robust and enlightened, but it's still incomplete because it too is single-dimensional whereas gender is multi-dimensional.
When classifying human beings in any subjective category (gender, race, class identity, religion, political affiliation, employment status, ethnic identity, sexual preference, amouressness, etc.), consider the multiple ways in which they may identify themselves. There isn't always a "check a single box" solution.
This goes beyond ideology. Trying to categorize a multi-dimensional entity into a single dimension is inaccurate, and inaccuracy has a cost.