当前位置:网站首页>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
边栏推荐
猜你喜欢

MySQL 用户授权

Programmers make money and practice, teach you how to do paid courses, self-media, paid articles and paid technical courses to make money

Path dependence: the poor hard science to counter attack breakthrough

JVM之GC 调优基础知识(一)

Participate in open source, let programmers regain their blood and passion

cnpm安装步骤

MySql fuzzy query Daquan

手把手教你彻底卸载MySQL

Teach you to completely uninstall MySQL

Nacos 原理
随机推荐
2022年比若依更香的开源项目
mysql basics (4)
最新版MySQL 8.0 的下载与安装(详细教程)
Concurrent Programming Review
The use of Conluce, an online document management system
Seata exception: endpoint format should like ip:port
报错:npm ERR code EPERM
[Koltin Flow (2)] The end operator of the Flow operator
手把手教你设计一个CSDN系统
Learn FPGA from the underlying structure (6) ---- Distributed RAM (DRAM, Distributed RAM)
Teach you to completely uninstall MySQL
MySQL(4)
排列数字(DAY90)dfs
WeChat payment and payment callback
[GLib] 什么是GType
子查询作为检索表时的不同使用场景以及是否需要添加别名的问题
每日练习------输出一个整数的二进制数、八进制数、十六进制数。
Falling ants (Peking University entrance exam questions)
idea 编译protobuf 文件的设置使用
Within the SQL connection table (link connections, left or right, cross connection, full outer join)