Mysql data type TIMESTAMP usage

Source: Internet
Author: User
Mysql data type TIMESTAMP usage in mysql database, timestamp data type is a special data type, you can automatically update the record timestamp as long as it is updated without using program updates.

Generally, the table has a Create date field, and other databases have default options. MySQL also has the default value timestamp. However, in MySQL, the value of timestamp is updated even if it is inserted or modified!

In this way, it is not the creation date. it is better to use it as an update date!

Therefore, to record the creation date in MySQL, you must use datetime and then use the NOW () function!

1: If the DEFAULT CURRENT_TIMESTAMP and on update CURRENT_TIMESTAMP clauses are available at the time of definition, the column value is the current timestamp by DEFAULT and is automatically updated.

2: If the DEFAULT or on update clause is not used, it is equivalent to DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP.

3: If only the DEFAULT CURRENT_TIMESTAMP clause is used and the on update clause is not used, the column value is the current timestamp by DEFAULT, but is not automatically updated.

4: If the DEFAULT clause is not used, but the on update CURRENT_TIMESTAMP clause exists, the column defaults to 0 and is automatically updated. (Www.jbxue.com)

5: If there is a constant value DEFAULT, this column will have a DEFAULT value and will not be automatically initialized as the current timestamp. If the column has an on update CURRENT_TIMESTAMP clause, the timestamp is automatically updated. Otherwise, the column has a default constant but will not be updated automatically.

You can use the current timestamp to Initialize values and automatically update values, or either of them. (For example, you can specify automatic update during definition, but it is not initialized .)

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.