Home > Database > Mysql Tutorial > How to modify the automatic generation time of a field in mysql

How to modify the automatic generation time of a field in mysql

coldplay.xixi
Release: 2020-12-01 09:47:53
Original
2826 people have browsed it

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.

How to modify the automatic generation time of a field in mysql

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 '创建时间' ;
Copy after login

--Modify CreateTime and set the default time CURRENT_TIMESTAMP

ALTER TABLE `table_name`
MODIFY COLUMN  `CreateTime` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ;
Copy after login

--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 '创建时间' ;
Copy after login

- -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 '创建时间' ;
Copy after login

2. MySQL tool settings

How to modify the automatic generation time of a field in mysql

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template