用于存储年份的MySQL类型:Smallint或Varchar或Date? [英] MySQL Type for Storing a Year: Smallint or Varchar or Date?
本文介绍了用于存储年份的MySQL类型:Smallint或Varchar或Date?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将在MySQL表中存储一年:是否最好将其存储为smallint或varchar?我认为,由于它不是一个完整的日期,日期格式不应该是一个答案,但我也会包括。
Smallint? varchar(4)?日期?
例如:
-
2008
1992
2053
解决方案
我会使用 YEAR (4)列类型...但是只有当期望的年份在范围1901和2155之内...否则,见Gambrinus的回答。
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 be an answer but I'll include that as well.
Smallint? varchar(4)? date? something else?
Examples:
解决方案
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.
这篇关于用于存储年份的MySQL类型:Smallint或Varchar或Date?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文