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;