MySQL Data type timestamp usage

Source: Internet
Author: User

In the MySQL database, the timestamp data type is a special data type that automatically updates the time as soon as the record is updated without using program updates timestamp.

There is usually a field in the table where create date is created, and other databases have the option of default values. MySQL also has a default value of timestamp, but in MySQL, not only is the insertion to be modified will also update the value of Timestamp!
In this way, it is not the date of creation, as the update date to use the better!
So to record the creation date in MySQL you have to use datetime and then use the now () function to complete!
1: If the default Current_timestamp and on UPDATE CURRENT_TIMESTAMP clauses are defined, the value of the column is the current timestamp, 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 there is only the default CURRENT_TIMESTAMP clause, and there is no on UPDATE clause, the column value defaults to the current timestamp but does not update automatically.
4: If the default clause is not used, but there is an on Update CURRENT_TIMESTAMP clause, the column defaults to 0 and is automatically updated. (www.jbxue.com)
5: If there is a constant value of default, the column will have a default value and will not be automatically initialized to the current timestamp. If the column also has an ON Update CURRENT_TIMESTAMP clause, the timestamp is updated automatically, otherwise the column has a default constant but does not update automatically.
You can use the current timestamp to initialize values and Automatic Updates, or either, or none. (For example, you can specify an automatic update when you define it, but not initialize it.) )

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.