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