Mysql method to modify fields to automatically generate time: 1. Add CreateTime to set the default time; 2. Modify CreateTime to set the default time; 3. Add UpdateTime to set the default time.
The operating environment of this tutorial: Windows 7 system, mysql version 8.0.22. This method is suitable for all brands of computers.
Related free learning recommendations: mysql video tutorial
Mysql method to modify fields to automatically generate time:
1. Mysql script implementation
--Add CreateTime to set the default timeCURRENT_TIMESTAMP
ALTER TABLE `table_name` ADD COLUMN `CreateTime` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ;
--Modify CreateTime and set the default time CURRENT_TIMESTAMP
ALTER TABLE `table_name` MODIFY COLUMN `CreateTime` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ;
--Add UpdateTime and set the default time CURRENT_TIMESTAMP Set the update time to ON UPDATE CURRENT_TIMESTAMP
ALTER TABLE `table_name` ADD COLUMN `UpdateTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间' ;
- -Modify UpdateTime and set the default time CURRENT_TIMESTAMP Set the update time to ON UPDATE CURRENT_TIMESTAMP
ALTER TABLE `table_name` MODIFY COLUMN `UpdateTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间' ;
2. MySQL tool settings
The above is the detailed content of How to modify the automatic generation time of a field in mysql. For more information, please follow other related articles on the PHP Chinese website!