What Data type should I use to store YYYY date format (4 character year only, no months or days)?
我应该使用什么数据类型来存储YYYY日期格式(仅4个字符年,没有月份或日期)?
2 个解决方案
#1
-1
I would suggest you using integer(4)
我建议你使用整数(4)
#2
1
You need if you table exist add a column on your structure of the table : example :
如果表存在,则需要在表的结构上添加一列:示例:
ALTER TABLE `table_name_to_alter` ADD `new_colum_name_year` YEAR NOT NULL AFTER `a_colum_name_exist`;
//YEAR NOT NULL the column is a type YEAR so XXXX only, and NOT NULL needed https://dev.mysql.com/doc/refman/5.7/en/year.html
// YEAR NOT NULL该列的类型为YEAR,因此仅限XXXX,并且需要NOT NULL https://dev.mysql.com/doc/refman/5.7/en/year.html
#1
-1
I would suggest you using integer(4)
我建议你使用整数(4)
#2
1
You need if you table exist add a column on your structure of the table : example :
如果表存在,则需要在表的结构上添加一列:示例:
ALTER TABLE `table_name_to_alter` ADD `new_colum_name_year` YEAR NOT NULL AFTER `a_colum_name_exist`;
//YEAR NOT NULL the column is a type YEAR so XXXX only, and NOT NULL needed https://dev.mysql.com/doc/refman/5.7/en/year.html
// YEAR NOT NULL该列的类型为YEAR,因此仅限XXXX,并且需要NOT NULL https://dev.mysql.com/doc/refman/5.7/en/year.html