pondělí 30. května 2016

In what data type to store year?

If you are using MySQL, use "year" data type, if possible. The reasons follows:
  1. It takes just 1 byte. Hence it saves storage.
  2. Date arithmetic can be applied without a conversion. Hence, it saves processor time.
  3. The reference point is well defined and unique. Hence, everyone can select the right attribute value for an event without any background knowledge (at least if you are a country that is using Gregorian calendar).
  4. Visualization and analytical tools automatically treat a "year" attribute as a temporal variable. That saves user's time.
But of course, "year" data type has some disadvantages. Namely, it has a narrow range of values. Hence, it can happen that the value you need to store is out of range. An example could be the year when an organization was established. On the other hand this limitation can work in your advantage - if someone types a year with 3 or 5 digits, the database will complain. And the database will be most likely right because the typed year is most likely a type.

Žádné komentáře:

Okomentovat