"MySQL" Automatically records creation date and update date

Source: Internet
Author: User

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!

So to record the creation date in MySQL you have to use datetime and then use the now () function to complete!

1,timestamp DEFAULT current_timestamp on UPDATE current_timestamp  
Refreshes the data column when creating new records and modifying existing records

2,timestamp DEFAULT current_timestamp  

This field is set to the current time when a new record is created, but it is not refreshed when you modify it later


3,timestamp on UPDATE current_timestamp set this field to 0 when creating a new record

"MySQL" Automatically records creation date and update date

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.