当前位置:网站首页>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
边栏推荐
- Is it reliable to open an account for stock trading on the mobile phone? Is it safe to open an account for stock trading on the Internet
- 低佣金免费开户渠道安全吗?
- From bitmap to bloom filter, C # implementation
- 我的c语言进阶学习笔记 ----- 关键字
- 墨者学院-X-Forwarded-For注入漏洞实战
- Big guys talk about the experience sharing of the operation of the cutting-edge mindspore open source community. Come up with a small notebook!
- 根据文件名批量生成文件夹
- Kubernetes visual interface dashboard
- Simulation of delta variant strain of novel coronavirus (mindsponge application)
- [microservice]eureka
猜你喜欢

Technical dry goods | top speed, top intelligence and minimalist mindspore Lite: help Huawei watch become more intelligent

技术干货|极速、极智、极简的昇思MindSpore Lite:助力华为Watch更加智能

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

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

Redis detailed tutorial

07 | 工作流设计:如何设计合理的多人开发模式?

Introduction to software engineering -- Chapter 4 -- formal description technology

Big guys talk about the experience sharing of the operation of the cutting-edge mindspore open source community. Come up with a small notebook!

Is there anyone who doesn't know the three cores of concurrent programming?

为什么EDR需要深度防御来打击勒索软件?
随机推荐
Technical dry goods | what is a big model? Oversized model? Foundation Model?
技术干货|极速、极智、极简的昇思MindSpore Lite:助力华为Watch更加智能
Target tracking shooting? Target occlusion shooting? With 1.9 billion installed petal apps, what unique features attract users?
Using physical information neural network to solve hydrodynamics equations
[test] the content of the hottest test development learning route has been updated again to help pass the customs and open the test of large factories
find_circ详细使用指南
剑指 Offer 10- II. 青蛙跳台阶问题
代码之外:写作是倒逼成长的最佳方式
Service discovery, storage engine and static website of go language
test
kubernetes可视化界面dashboard
Can I open an account for stock trading on my mobile phone? Is it safe to open an account for stock trading on the Internet
利用burp精准定位攻击者
Nacos安装指南
股票怎样在手机上开户安全吗 网上开户炒股安全吗
入侵痕迹清理
Your connection is not private
2022健康博览会,山东养生保健展会,产后健康、睡眠健康展
My advanced learning notes of C language ----- keywords
论文解读(LG2AR)《Learning Graph Augmentations to Learn Graph Representations》