MySQL Type for Storing a Year: Smallint or Varchar or Date?

前端 未结 3 780
春和景丽
春和景丽 2021-01-07 19:29

I will be storing a year in a MySQL table: Is it better to store this as a smallint or varchar? I figure that since it\'s not a full date, that the date format shouldn\'t

3条回答
  •  青春惊慌失措
    2021-01-07 20:03

    I would use the YEAR(4) column type... but only if the years expected are within the range 1901 and 2155... otherwise, see Gambrinus's answer.

提交回复
热议问题