MySQL Auto get time date

Source: Internet
Author: User

Implementation method:

1. Set the field type to TIMESTAMP

2. Set the default value to current_timestamp

Examples of applications:

1. MySQL Script Implementation use case

-- add Createtime Set default time current_timestamp

ALTER TABLE ' table_name '
ADD COLUMN ' createtime ' datetime NULL DEFAULT current_timestamp COMMENT ' creation time ';

--Modify Createtime Set default time current_timestamp
ALTER TABLE ' table_name '
MODIFY COLUMN ' createtime ' datetime NULL DEFAULT current_timestamp COMMENT ' creation time ';

-- add UpdateTime Set default time current_timestamp set update time to on update current_timestamp
ALTER TABLE ' table_name '
ADD COLUMN ' updatetime ' timestamp NULL DEFAULT current_timestamp on UPDATE current_timestamp COMMENT ' creation time ';

--Modify UpdateTime Set default time current_timestamp set update time is on update current_timestamp

ALTER TABLE ' table_name '
MODIFY COLUMN ' updatetime ' timestamp NULL DEFAULT current_timestamp on UPDATE current_timestamp COMMENT ' creation time ';

2. mysql Tool settings

Summarize:

1, MySQL automatic management, maintain and database time consistency;

2, simple and efficient, do not need application development support, MySQL automatic completion;

MySQL Auto get time 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.