当前位置:网站首页>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
边栏推荐
- MySQL笔记2(函数,约束,多表查询,事务)
- DPW-SDNet: Dual Pixel-Wavelet Domain Deep CNNsfor Soft Decoding of JPEG-Compressed Images
- ML.NET相关资源整理
- 活动推荐 | 2022年深圳最值得参加的边缘计算活动
- Enhancing Quality for HEVC Compressed Videos
- vlan简单实验
- 【深度学习】对迁移学习中域适应的理解和3种技术的介绍
- 【网络安全专栏目录】--企鹅专栏导航
- CISP-PTE真题演示
- Why do so many people who teach themselves software testing give up later...
猜你喜欢
MySQL 用户授权
MySQL笔记1(数据库的好处,数据库的概念,数据库的特点,MySQL的启动,数据模型,SQL)
opencv,numpy,tensor格式转换
MySql创建数据表
GPGGA NTRIP RTCM Notes
[The Beauty of Software Engineering - Column Notes] 31 | Is software testing responsible for product quality?
openim支持十万超级大群
【Network Security Column Directory】--Penguin Column Navigation
ClickHouse 数据插入、更新与删除操作 SQL
【菜鸡含泪总结】如何用pip、anaconda安装库
随机推荐
navicat连接MySQL报错:1045 - Access denied for user ‘root‘@‘localhost‘ (using password YES)
Enhancing Quality for HEVC Compressed Videos
系统结构考点之流水线向量点积
mysql死锁
How do I refresh the company's background management system (Part 1) - performance optimization
我是如何让公司后台管理系统焕然一新的(上) -性能优化
系统结构考点之PM2I单级网络
Teach you how to build a permanently running personal server
MySQL60 homework
关于SFML Rect.inl文件报错的问题
Markdown的使用
你需要知道的ES6—ES13开发技巧
vlan简单实验
3分钟带你了解微信小程序开发
About the data synchronization delay of MySQL master-slave replication
共用体、共用体与结构体的区别、枚举之C语言犄角旮旯的知识
Deep Non-Local Kalman Network for VideoCompression Artifact Reduction
关于MySQL主从复制的数据同步延迟问题
[The Beauty of Software Engineering - Column Notes] 31 | Is software testing responsible for product quality?
GPGGA NTRIP RTCM Notes