当前位置:网站首页>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-06-27 00:26:00 【Jiangtaixiaobai】
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 it's in navicat In case of operation , Set the field type to timestamp, Write default CURRENT_TIMESTAMP, Here's the picture :
2、 Add a new column to an existing table
ALTER TABLE table1
ADD COLUMN `createtime` timestamp NULL DEFAULT CURRENT_TIMESTAMP
3、 Modify a column to time format and add default values
alter table table1
change createtime newtime timestamp null default current_timestamp
4、 Show milliseconds
If you want to record to milliseconds , Set up CURRENT_TIMESTAMP(3) that will do
边栏推荐
- Outside the code: writing is the best way to force growth
- 05 | 规范设计(下):commit 信息风格迥异、难以阅读,如何规范?
- Introduction to message queuing
- [microservice]eureka
- 论文解读(LG2AR)《Learning Graph Augmentations to Learn Graph Representations》
- Common techniques of email attachment phishing
- 从位图到布隆过滤器,C#实现
- From bitmap to bloom filter, C # implementation
- MindSpore新型轻量级神经网络GhostNet,在ImageNet分类、图像识别和目标检测等多个应用场景效果优异!
- 不会写免杀也能轻松过defender上线CS
猜你喜欢

Le principe le plus complet de formation à la précision hybride pour l'ensemble du réseau

matlab数据类型 —— 字符型

墨者学院-SQL注入漏洞测试(报错盲注)

大咖讲 | 最前沿的昇思MindSpore开源社区运营的经验分享,快拿出小本本记录呀!

Simple and fast digital network (network dolls in the network)

当Transformer遇见偏微分方程求解

The most complete hybrid precision training principle in the whole network

Redis detailed tutorial

利用burp精准定位攻击者

Installation of xshell and xftp
随机推荐
Pet hospital management system based on SSMP
Introduction to message queuing
Understanding of "the eigenvectors corresponding to different eigenvalues cannot be orthogonalized"
Installation of xshell and xftp
墨者学院-SQL注入漏洞测试(报错盲注)
手机炒股靠谱吗 网上开户炒股安全吗
Is it reliable to speculate in stocks by mobile phone? Is it safe to open an account and speculate in stocks online
The fourth bullet of redis interview eight part essay (end)
Is the low commission free account opening channel safe?
How to write test cases and a brief introduction to go unit test tool testify
MindSpore新型轻量级神经网络GhostNet,在ImageNet分类、图像识别和目标检测等多个应用场景效果优异!
“message“:“Bad capabilities. Specify either app or appTopLevelWindow to create a session“
Amway! How to provide high-quality issue? That's what Xueba wrote!
Sword finger offer 10- ii Frog jumping on steps
指南针开户安全的吗?
Your connection is not private
技术干货|极速、极智、极简的昇思MindSpore Lite:助力华为Watch更加智能
冲刺强基计划数学物理专题二
复杂数据没头绪?
Oracle 數據庫基本知識概念