当前位置:网站首页>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
边栏推荐
- Apache DolphinScheduler新一代分布式工作流任务调度平台实战-上
- [Limited Time Bonus] 21-Day Learning Challenge - MySQL from entry to mastery
- Use the map function to operate on each element in the list It seems that you don't need a map
- Why do so many people who teach themselves software testing give up later...
- JDBC (detailed explanation)
- 系统结构考点之流水线向量点积
- 类和对象——上
- 【Network Security Column Directory】--Penguin Column Navigation
- Markdown的使用
- 活动推荐 | 2022年深圳最值得参加的边缘计算活动
猜你喜欢

How do I refresh the company's background management system (Part 1) - performance optimization

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

c语言进阶篇:指针(五)

navicat新建数据库

这本记述40年前历史的游戏书,预言的却是当下的事

MySQL 有这一篇就够(呕心狂敲37k字,只为博君一点赞!!!)

数据指标口径不统一、重复开发?亿信ABI指标管理平台帮你解决

Outsourcing worked for three years, it was abolished...

【菜鸡含泪总结】如何用pip、anaconda安装库

Deep Non-Local Kalman Network for VideoCompression Artifact Reduction
随机推荐
About the error of SFML Rect.inl file
Outsourcing worked for three years, it was abolished...
Teach you how to build a permanently running personal server
Chrome 配置samesite=none方式
深入浅出边缘云 | 3. 资源配置
Apache DolphinScheduler新一代分布式工作流任务调度平台实战-
Enhancing Quality for HEVC Compressed Videos
KingbaseESV8R6 snapshot too old的配置和测试
类似 MS Project 的项目管理工具有哪些
openim支持十万超级大群
三层架构简单配置
类和对象——上
ClickHouse 数据插入、更新与删除操作 SQL
opencv,numpy,tensor格式转换
Swift RegexBuilder Vs. Raku Grammar
How strict Typescript strict mode?
微信公众号授权登录后报redirect_uri参数错误的问题
拿什么来保护数据安全?基层数据安全体系建设待提升
[Deep Learning] Target Detection | SSD Principle and Implementation
数字货币期货现货交易技巧,把握关键进场的买入点!(纯干货)