The year function in MySQL

Source: Internet
Author: User
Tags deprecated

It is generally assumed that the year type occupies 1 bytes, and you can specify that the display width is year (4) or year (2) when defined,but starting with MySQL5.6.6 , year (2) type is automatically swapped for year (4) and year (2) type is disabled.

(i) year (2) type is automatically replaced as year (4)

Mysql>drop table if exists t;

Query ok,0 rows Affected (0.01 sec)

Mysql>create table T (a year (2));

Query ok,0 rows affected, 1 Warning (0.00 sec)

Mysql>show Warnings\g;

1. Row ***************************

Level:warning

code:1818

Message:year (2) column type is deprecated. Creating year (4) column instead.

1 Row Inset (0.00 sec)

ERROR:

No queryspecified

Mysql>explain T;

+-------+---------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+-------+---------+------+-----+---------+-------+

| A | Year (4) |     YES | |       NULL | |

+-------+---------+------+-----+---------+-------+

1 Row Inset (0.00 sec)

Mysql>insert into T select ' 14 ';

Query ok,1 Row Affected (0.00 sec)

Records:1 duplicates:0 warnings:0

Mysql>select * from T;

+------+

| A |

+------+

| 2014 |

+------+

1 Row Inset (0.00 sec)

Mysql>

(ii) the Year (2) type that exists in the current table is still present and processed as year (2), but the following methods are automatically converted to year (4):

(1) ALTER TABLE

ALTER TABLE statements with the resulting rebuild tables:

Mysql> ALTER TABLE T modify a year (2);

Query OK, 0 rows affected, 1 Warning (0.00 sec)

records:0 duplicates:0 warnings:1


Mysql> explain t;

+-------+---------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+-------+---------+------+-----+---------+-------+

| A | Year (4) |     YES | |       NULL | |

+-------+---------+------+-----+---------+-------+

1 row in Set (0.00 sec)


Mysql> ALTER TABLE T modify a year (2);

Query OK, 0 rows affected, 1 warning (0.01 sec)

records:0 duplicates:0 warnings:1


Mysql> Show warnings;

+---------+------+---------------------------------------------------------------------+

| Level | Code | Message |

+---------+------+---------------------------------------------------------------------+

| Warning | 1818 | Year (2), column type is deprecated. Creating year (4) column instead. |

+---------+------+---------------------------------------------------------------------+

1 row in Set (0.01 sec)

(2) Peair TABLE

If the database finds a table that contains the year (2) column when the check table is found, it is recommended that you make use of this (4).

(3) Mysql_upgrade

This is used for repair table cases.

(4) When dump files and reload dump files, the affected data values will have a potential impact on dump and load.

The year function in MySQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.