MySQL field value auto update time

Source: Internet
Author: User

It may appear in the production environment, the project is online, but the Update Time field is not assigned, that is, the update time is still null each time the data is updated. In order to solve this problem, the update time is usually updated when the program updates the data. But after the online change process needs to be re-upgraded, very troublesome. You can now ensure that the updated time of the data is updated automatically each time you update the data by modifying the field of the update time.
The update time is automatically updated by executing the following SQL on an already built table:

ALTER TABLE checker_barcode  MODIFY COLUMN update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP 

One of the things to note is:
1, replace "Checker_barcode" with the name of the table you need to update, replace "Update_time" with the name of the field you need to update, and the rest of SQL will not change.
2. After executing this SQL, all the update_time values in the table are null, and update_time all become the current time.
3, when executing the UPDATE statement, if the data does not really change, the Update_time value is unchanged, only the data value changes, Update_time will become the current time.

MySQL field value auto update time

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.