Mysql automatically obtains the time date and mysql obtains the time date.

Source: Internet
Author: User

Mysql automatically obtains the time date and mysql obtains the time date.

Implementation Method:

 

1. Set the field typeTIMESTAMP

2. Set the default valueCURRENT_TIMESTAMP

 

Example application:

 

1. MySQL script implementation case

--Add CreateTime to set the default timeCURRENT_TIMESTAMP

Alter table 'table _ name'
Add column 'createtime' datetime NULLDEFAULT CURRENT_TIMESTAMPCOMMENT 'creation time ';

 

-- Modify CreateTime to set the default time CURRENT_TIMESTAMP
Alter table 'table _ name'
Modify column 'createtime' datetime NULLDEFAULT CURRENT_TIMESTAMPCOMMENT 'creation time ';

 

--Add UpdateTime to set the default timeCURRENT_TIMESTAMP: Set the update timeOn update CURRENT_TIMESTAMP
Alter table 'table _ name'
Add column 'updatetime' timestamp NULLDEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPCOMMENT 'creation time ';

 

-- Modify UpdateTime to set the default timeCURRENT_TIMESTAMP: Set the update timeOn update CURRENT_TIMESTAMP

Alter table 'table _ name'
Modify column 'updatetime' timestamp NULLDEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPCOMMENT 'creation time ';

2. MySQL tool settings

 

 

Summary:

 

1. MySQL is automatically managed to maintain time consistency with the database;

2. Simple and efficient. MySQL is automatically completed without application development support;

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.