Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to modify the automatic generation time of fields by mysql

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report