How to modify the automatic generation time of fields by mysql
Editor to share with you how mysql modifies the automatic generation time of fields. I hope you will gain a lot after reading this article. Let's discuss it together.
Mysql modify field automatic generation time method: 1, add CreateTime to set the default time; 2, modify the CreateTime setting default time; 3, add UpdateTime to set the default time.
Mysql method to modify the automatic generation time of fields:
1. Mysql script implementation
-- add CreateTime to set the default time CURRENT_TIMESTAMP
ALTER TABLE `table_ name`add COLUMN `CreateTime` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'creation time'
-- modify CreateTime to set the 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 setting default time CURRENT_TIMESTAMP set update time to ON UPDATE CURRENT_TIMESTAMP
ALTER TABLE `table_ name`MODIFY COLUMN `UpdateTime`creation time'
2. MySQL tool settings
After reading this article, I believe you have a certain understanding of how mysql modifies the automatic generation time of fields. You want to know more about it. Welcome to follow the industry information channel. Thank you for your reading!