Mysql field value automatic update time_mysql

Source: Internet
Author: User
In the production environment, the project has been launched, but the update time field is not assigned a value. that is to say, the update time of this data item is still null every time it is updated. To solve this problem, the update time is usually updated when the program updates data. However, after the data is released, it may appear in the production environment. The project is launched, but the update time field is not assigned a value. that is to say, the update time is still null every time this data is updated. To solve this problem, the update time is usually updated when the program updates data. However, it is quite troublesome to update the program after it is released. Now, you can modify the update time field to ensure that the data update time is automatically updated each time the data is updated.
Execute the following SQL statement on a created table to automatically update the update time:

Alter table checker_barcode modify column update_time timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP

Note the following:
1. replace "checker_barcode" with the name of the table to be updated, and "update_time" with the name of the field to be updated. The remaining SQL statements remain unchanged.
2. after the SQL statement is executed, all the data whose update_time value is null in the table is changed to the current time.
3. when an update statement is executed, if the data does not change, the update_time value remains the same. only when the data value changes, the update_time value changes to the current time.

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.