当前位置:网站首页>mysql 时间字段默认设置为当前时间
mysql 时间字段默认设置为当前时间
2022-07-30 21:21:00 【m0_54853420】
1、直接在创建表时添加该列并声明默认值,如下:
CREATE TABLE `table1` (
`id` int(11) NOT NULL,
`createtime` timestamp NULL default CURRENT_TIMESTAMP,
`updatetime` timestamp NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
如果是在navicat下操作的话,设置字段的类型为timestamp,默认值写上CURRENT_TIMESTAMP,如下图:

2、在现有表中添加新列
ALTER TABLE table1
ADD COLUMN `createtime` timestamp NULL DEFAULT CURRENT_TIMESTAMP
3、 修改某一列为时间格式并添加默认值
alter table table1
change createtime newtime timestamp null default current_timestamp
4、展示毫秒
如果想记录到毫秒,设置CURRENT_TIMESTAMP(3)即可
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- Image Restoration by Estimating Frequency Distribution of Local Patches
- About the data synchronization delay of MySQL master-slave replication
- ENS 表情包域名火了!是炒作还是机遇?
- 深入浅出边缘云 | 3. 资源配置
- Knowledge of C language corners of byte alignment
- [Nuxt 3] (十三) Nuxt 是如何工作的?
- [Deep Learning] Understanding of Domain Adaptation in Transfer Learning and Introduction of 3 Techniques
- ClickHouse 数据插入、更新与删除操作 SQL
- 微信公众号授权登录后报redirect_uri参数错误的问题
- Apache DolphinScheduler新一代分布式工作流任务调度平台实战-
猜你喜欢

Typescript 严格模式有多严格?

用于视频压缩伪影消除的深度卡尔曼滤波网络

kubernetes

【Nacos】解决Nacos下载速度缓慢的问题

LeetCode·每日一题·952.按公因数计算最大组件大小·并查集

LeetCode · 23. Merge K ascending linked lists · recursion · iteration
![[The Beauty of Software Engineering - Column Notes] 31 | Is software testing responsible for product quality?](/img/6a/640763e3bd6c28f3e7fa762798b0ae.png)
[The Beauty of Software Engineering - Column Notes] 31 | Is software testing responsible for product quality?

KingbaseES TOAST存储方式

Image Restoration by Estimating Frequency Distribution of Local Patches

Deep Non-Local Kalman Network for VideoCompression Artifact Reduction
随机推荐
LeetCode · 23. Merge K ascending linked lists · recursion · iteration
MySQL60题作业
WinDbg实践--入门篇
GPGGA NTRIP RTCM Notes
【限时福利】21天学习挑战赛 - MySQL从入门到精通
Outsourcing worked for three years, it was abolished...
导航栏----个人中心 Dropdown
数据质量提升
[Deep Learning] Understanding of Domain Adaptation in Transfer Learning and Introduction of 3 Techniques
openim支持十万超级大群
走进Redis,让你重新认识redis。绝不是表面
触摸屏状态机
在IDEA中使用JUnit4和JUnitGenerator V2.0自动生成测试模块
手动从0搭建ABP框架-ABP官方完整解决方案和手动搭建简化解决方案实践
Structured Streaming报错记录:Overloaded method foreachBatch with alternatives
awk笔记
kubernetes
基于ABP实现DDD--仓储实践
转义字符笔记记录
活动推荐 | 2022年深圳最值得参加的边缘计算活动