当前位置:网站首页>The mysql time field is set to the current time by default
The mysql time field is set to the current time by default
2022-07-30 21:32:00 【m0_54853420】
1. Add the column directly when creating the table and declare the default value, as follows:
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;
If you are operating under navicat, set the field type to timestamp, and write the default value to CURRENT_TIMESTAMP, as shown below:

2. Add a new column to an existing table
ALTER TABLE table1
ADD COLUMN `createtime` timestamp NULL DEFAULT CURRENT_TIMESTAMP
3. Modify the time format of a column and add a default value
alter table table1
change createtime newtime timestamp null default current_timestamp
4, display milliseconds
If you want to record to milliseconds, set CURRENT_TIMESTAMP(3)
Let me introduce myself first. The editor graduated from Shanghai Jiaotong University in 2013. I worked in a small company and went to big factories such as Huawei and OPPO. I joined Alibaba in 2018, until now.I know that most junior and intermediate java engineers want to upgrade their skills, they often need to explore their own growth or sign up to study, but for training institutions, the tuition fee is nearly 10,000 yuan, which is really stressful.Self-learning that is not systematic is very inefficient and lengthy, and it is easy to hit the ceiling and the technology stops.Therefore, I collected a "full set of learning materials for java development" for everyone. The original intention is also very simple. I hope to help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden.Add the business card below to get a full set of learning materials
边栏推荐
猜你喜欢
![[Deep Learning] Target Detection | SSD Principle and Implementation](/img/07/ea4ff3ffbe7e0c11ff7baec0e1818f.jpg)
[Deep Learning] Target Detection | SSD Principle and Implementation

【信息安全技术】RSA算法的研究及不同优化策略的比较

【零代码工具】15 款企业级零代码开发平台推荐,总有一款是你心仪的

A simple rich text editor

手动从0搭建ABP框架-ABP官方完整解决方案和手动搭建简化解决方案实践

一个网络两种用途!南开&哈工程提出TINet,通过细化纹理和边缘,在显著性目标检测和伪装目标检测上实现双SOTA!...

mysql死锁

GPGGA NTRIP RTCM 笔记

外包干了三年,废了...

MySQL 灵魂 16 问,你能撑到第几问?
随机推荐
GPGGA NTRIP RTCM 笔记
qt使用动态库(DLL)
MySQL60题作业
Quick Master QML Chapter 6 Animation
【Nacos】解决Nacos下载速度缓慢的问题
kubernetes
[Nuxt 3] (十四) Nuxt 生命周期
【限时福利】21天学习挑战赛 - MySQL从入门到精通
【菜鸡含泪总结】如何用pip、anaconda安装库
你需要知道的ES6—ES13开发技巧
ML.NET相关资源整理
【机器学习】梯度下降背后的数学之美
mysql deadlock
冲刺第六周
[Deep Learning] Understanding of Domain Adaptation in Transfer Learning and Introduction of 3 Techniques
QUALITY-GATED CONVOLUTIONAL LSTM FOR ENHANCING COMPRESSED VIDEO
JSESSIONID description in cookie
LeetCode·23.合并K个升序链表·递归·迭代
关于SFML Rect.inl文件报错的问题
Google Earth Engine ——我们如何筛选一个列表中的排序以时间为例