SQL DataType - How to store a year?

peter picture peter · Mar 30, 2009 · Viewed 99.2k times · Source

I need to insert a year(eg:1988 ,1990 etc) in a database. When I used Date or Datetime data type, it is showing errors. Which datatype should I use.

Answer

KM. picture KM. · Mar 30, 2009

regular 4 byte INT is way to big, is a waste of space!

You don't say what database you're using, so I can't recommend a specific datatype. Everyone is saying "use integer", but most databases store integers at 4 bytes, which is way more than you need. You should use a two byte integer (smallint on SQL Server), which will conserve space better.