Home  >  Article  >  Database  >  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
coldplay.xixiOriginal
2020-12-01 09:47:532806browse

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

--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

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!

Statement:
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

Related articles

See more