当前位置:网站首页>mysql time field is set to current time by default
mysql time field is set to current time by default
2022-07-30 06:06:00 【Mmm okay!】
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
边栏推荐
- 75. 颜色分类
- [Mysql] DATEDIFF function
- Solve the problem that the local nacos is not configured but the localhost8848 connection exception always occurs
- Error: npm ERR code EPERM
- 面试题 17.13. 恢复空格(字典树)
- MySQL的存储过程
- [Mysql] CONVERT函数
- net start mysql MySQL 服务正在启动 . MySQL 服务无法启动。 服务没有报告任何错误。
- MySql string splitting realizes the split function (field splitting, column switching, row switching)
- [Koltin Flow (2)] The end operator of the Flow operator
猜你喜欢
腾讯面试居然跟我扯了半小时的CountDownLatch
从驱动表和被驱动表来快速理解MySQL中的内连接和外连接
4、nerf(pytorch)
navicat连接MySQL报错:1045 - Access denied for user ‘root‘@‘localhost‘ (using password YES)
【图像检测】基于灰度图像的积累加权边缘检测方法研究附matlab代码
MySQL 用户授权
瑞吉外卖项目:新增菜品与菜品分页查询
Navicat new database
应用实践 | Apache Doris 在百度智能云计费账单系统的应用实践
WeChat payment and payment callback
随机推荐
JVM 类加载机制 超详细学习笔记(三)
[Mysql] DATEDIFF函数
2022年SQL大厂高频实战面试题(详细解析)
"Hou Lang" programmer version, a speech dedicated to a new generation of programmers, He Bing's "Hou Lang" speech imitation show
2022 SQL big factory high-frequency practical interview questions (detailed analysis)
It is enough for MySQL to have this article (37k words, just like Bojun!!!)
MySQL stored procedure
MySQL索引从入门到深入学习
cnpm安装步骤
MySQL kills 10 questions, how many questions can you stick to?
Docker-compose install mysql
分布式事务之 Seata框架的原理和实战使用(三)
MySQL (2)
MySQL 有这一篇就够(呕心狂敲37k字,只为博君一点赞!!!)
微信小程序开发学习
[Mysql] DATEDIFF function
报错:npm ERR code EPERM
使用DataEase开源工具制作一个高质量的数据大屏
MySQL-Explain详解
The Golden Circle Rule: Deep Thinking Methods for Successful People