YEAR类型,可以定义为YEAR(4) or YEAR(2),但是表现方式
不一致,如下:
As a 4-digit string in the range '1901' to '2155'.
As a 4-digit number in the range 1901 to 2155.
As a 1- or 2-digit string in the range '0' to '99'. Values in the ranges '0' to '69' and '70' to '99' are converted to YEAR values in the ranges 2000 to 2069 and 1970 to 1999.
As a 1- or 2-digit number in the range 1 to 99. Values in the ranges 1 to 69 and 70 to 99 are converted to YEAR values in the ranges 2001 to 2069 and 1970 to 1999.
备注小记:
timestamp除了上面的时区问题,还有一个有趣的现象。
mysql> create table t2date_zsd(time1 timestamp not null,time2 timestamp not null); Query OK, 0 rows affected (0.06 sec) mysql> show create table t2date_zsd; +------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | t2date_zsd | CREATE TABLE `t2date_zsd` ( `time1` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `time2` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 | +------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)mysql>
从上述例子来看,如果不设置default,它默认给你current_timestamp另外赋予零值表示,而且timestamp不能同时CURRENT_TIMESTAMP或者now()存在,否则会报表定义错误(Incorrect table definition)