mysql修改字段自动生成时间的方法:1、添加createtime设置默认时间;2、修改createtime设置默认时间;3、添加updatetime设置默认时间。
本教程操作环境:windows7系统、mysql8.0.22版,该方法适用于所有品牌电脑。
相关免费学习推荐:mysql视频教程
mysql修改字段自动生成时间的方法:
1、mysql脚本实现
--添加createtime 设置默认时间 current_timestamp
alter table `table_name`add column `createtime` datetime null default current_timestamp comment '创建时间' ;
--修改createtime 设置默认时间 current_timestamp
alter table `table_name`modify column `createtime` datetime null default current_timestamp comment '创建时间' ;
--添加updatetime 设置 默认时间 current_timestamp 设置更新时间为 on update current_timestamp
alter table `table_name`add column `updatetime` timestamp null default current_timestamp on update current_timestamp comment '创建时间' ;
--修改 updatetime 设置 默认时间 current_timestamp 设置更新时间为 on update current_timestamp
alter table `table_name`modify column `updatetime` timestamp null default current_timestamp on update current_timestamp comment '创建时间' ;
2、mysql工具设置
以上就是mysql如何修改字段自动生成时间的详细内容。