SQL DataType - How to store a year?

前端 未结 9 887
没有蜡笔的小新
没有蜡笔的小新 2020-12-03 06:27

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.

相关标签:
9条回答
  • 2020-12-03 07:21

    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.

    0 讨论(0)
  • 2020-12-03 07:21

    you are trying to insert a year in the database then use:
    type YEAR

    0 讨论(0)
  • 2020-12-03 07:22

    Use integer if all you need to store is the year. You can also use datetime if you think there will be date based calculations while querying this column

    0 讨论(0)
提交回复
热议问题