当前位置:网站首页>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
边栏推荐
- 当Transformer遇见偏微分方程求解
- 【UVM实战 ===> Episode_3 】~ Assertion、Sequence、Property
- com.fasterxml.jackson.databind.exc.MismatchedInputException: Expected array or string. at [Source:x
- Is it safe to open an account on the mobile phone to buy stocks? Is it safe to open an account on the Internet to speculate in stocks
- [微服务]Nacos
- Is it safe to open a compass account?
- 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
- 新型冠状病毒变异Delta毒株的模拟(MindSPONGE应用)
- 1+1<2 ?! HESIC论文解读
- 05 | 规范设计(下):commit 信息风格迥异、难以阅读,如何规范?
猜你喜欢

全網最全的混合精度訓練原理

CPU的异常处理

CVE-2022-30190 Follina Office RCE分析【附自定义word模板POC】

根据文件名批量生成文件夹

新型冠状病毒变异Delta毒株的模拟(MindSPONGE应用)

Lorsque le transformateur rencontre l'équation différentielle partielle

Competition Registration | one of the key ai+ scientific computing competitions - China open source scientific software creativity competition, competing for 100000 bonus!

The most complete hybrid precision training principle in the whole network

泰国安全又划算的支付方式

技术干货|极速、极智、极简的昇思MindSpore Lite:助力华为Watch更加智能
随机推荐
简单快速的数网络(网络中的网络套娃)
com.fasterxml.jackson.databind.exc.MismatchedInputException: Expected array or string. at [Source:x
CPU的异常处理
PHP code audit series (I) basis: methods, ideas and processes
一篇文章带你学会容器逃逸
这3个并发编程的核心,竟然还有人不知道?
1+1<2 ?! HESIC论文解读
Concepts de base de données Oracle
深度学习方法求解平均场博弈论问题
Super hard core! Can the family photo album on Huawei's smart screen be classified automatically and accurately?
【leetcode】275. H index II
Freescale 单片机概述
1+1<2 ?! Interpretation of hesic papers
In depth understanding of UDP in the transport layer and the use of UDP in sockets
串口调试工具 mobaxterm 下载
Analysis on the advantages and disadvantages of the best 12 project management systems at home and abroad
网络中的网络(套娃)
JS library for number formatting
Lorsque le transformateur rencontre l'équation différentielle partielle
Deep learning method for solving mean field game theory problems