当前位置:网站首页>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
边栏推荐
- [Nuxt 3] (十四) Nuxt 生命周期
- ML.NET相关资源整理
- 这本记述40年前历史的游戏书,预言的却是当下的事
- mysql死锁
- QUALITY-GATED CONVOLUTIONAL LSTM FOR ENHANCING COMPRESSED VIDEO
- MySQL笔记1(数据库的好处,数据库的概念,数据库的特点,MySQL的启动,数据模型,SQL)
- ValueError: Append mode is not supported with xlsxwriter解决方案
- 共用体、共用体与结构体的区别、枚举之C语言犄角旮旯的知识
- 用于命名实体识别的模块化交互网络
- Use the map function to operate on each element in the list It seems that you don't need a map
猜你喜欢

【深度学习】目标检测|SSD原理与实现

解决centos8 MySQL密码问题ERROR 1820 (HY000) You must reset your password using ALTER USER

DPW-SDNet: Dual Pixel-Wavelet Domain Deep CNNsfor Soft Decoding of JPEG-Compressed Images

What is the common factor

用于命名实体识别的模块化交互网络

A simple rich text editor

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

QUALITY-GATED CONVOLUTIONAL LSTM FOR ENHANCING COMPRESSED VIDEO

Google Earth Engine ——ee.List.sequence函数的使用

Typescript 严格模式有多严格?
随机推荐
socket:内核初始化及创建流(文件)详细过程
基于ABP实现DDD--实体创建和更新
Apache DolphinScheduler新一代分布式工作流任务调度平台实战-
[Machine Learning] The Beauty of Mathematics Behind Gradient Descent
uni-app开发微信小程序踩坑
ELF: Loading process
Structured Streaming报错记录:Overloaded method foreachBatch with alternatives
[Nuxt 3] (十三) Nuxt 是如何工作的?
基于ABP实现DDD--领域服务、应用服务和DTO实践
y82.第四章 Prometheus大厂监控体系及实战 -- 监控扩展和prometheus 联邦(十三)
系统结构考点之并行主存
CISP-PTE真题演示
深入浅出富文本编辑器
[Nuxt 3] (十四) Nuxt 生命周期
类似 MS Project 的项目管理工具有哪些
navicat连接MySQL报错:1045 - Access denied for user ‘root‘@‘localhost‘ (using password YES)
关于SFML Rect.inl文件报错的问题
这本记述40年前历史的游戏书,预言的却是当下的事
【限时福利】21天学习挑战赛 - MySQL从入门到精通
LeetCode·Daily Question·952. Calculate Maximum Component Size by Common Factor·Union Check