MySQL add age column

I found a few weird stuff on the databases I have been working with lately.

one of the weird stuff: signed integer types used for age columns ...
I am not going to argue with it ... I will just laugh and I am sure that a few friends reading this blog will laugh with it as well.


So, what type would I use for a human age column on a MySQL DB?
Hmm, UNSIGNED TINYINT --a Byte ...
I don't see any human making it to over 255 years old in the next 50 years --I hope I am wrong on this

Adding an age field.
mysql> ALTER TABLE ppl ADD age TINYINT UNSIGNED;
Query OK, 34292 rows affected (1.08 sec)
Records: 34292  Duplicates: 0  Warnings: 0


The statement above should add a TINYINT(3) by default where 3 is the maximum display digit --I think

You can control the position of the `new` collumn within the table with AFTER, eg:
mysql> ALTER TABLE ppl ADD age TINYINT UNSIGNED AFTER lastname;


On second thought , if I was designing the DBs I would prefer to not even use an age column and use a birth-date instead, and then produce the age to the reports that need it with some MySQL date arithmetic function and replace older than logic with was born before logic where appropriate.





Age Field Type on a DB joke