by.jml

Posts

Storing Human Sexes in Database

While designing a database that deals with human information records such as name, birth date, and age, I have faced a dilemma of the proper column format for human sexes.

I could use BOOLEAN datatype (true for female, false for men), but there are clinically more sexes than these two. Using ENOM or VARCHAR is out of the question as localization will break the data integrity.

The most sensual solution seems using TINYINT and assigning a number for each number, and this is exactly the standard ISO/IEC 5218:2004 recommends:

ISO/IEC 5218:2004 specifies a uniform representation of human sexes for the interchange of information. It provides a set of numeric codes that are independent of language-derived codes and as such is intended to provide a common basis for the international exchange of information containing human sex data.

ISO/IEC 5218:2004 Document specifies the sex codes as:

  • 0 = not known;
  • 1 = male;
  • 2 = female;
  • 9 = not applicable.

However, the document makes it clear that it does not place significance on the assignment of the number 1 to male and 2 to female and leaves to member countries to decide this.