当前位置:网站首页>mysql automatically adds creation time and update time
mysql automatically adds creation time and update time
2022-07-31 11:07:00 【m0_54853503】
A climber who is aiming at the top will not be intoxicated by a certain footprint along the way. In the world of code farmers, the beautiful application experience comes from the programmer's handling of details and the realm of self-requirement. Young peopleHe is also one of the busy code farmers. Every day and every week, he leaves some footprints. It is the content of these creations. There is a kind of persistence.
1 Description
In mysql, when the column type in the added table is the time type (timestamp), the default value can be set
Set the default value of the time column to automatically get the creation time:
default CURRENT_TIMESTAMPSet the default value of the time column to get the update time automatically:
default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMPAdd another value that cannot be null
#Create timenot null default CURRENT_TIMESTAMP# update timenot null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP2 full operational SQL
2.1 Modify the default value of the time column in the existing table to be obtained automatically
Modify the create_time column in the table t_user to set the current system time if the value is empty when inserting new data
#Modify the create_time column in the table t_user When inserting new data, if the value is empty, it will be set to the current system timeALTER TABLE t_user MODIFY create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time';Modify the update_time column in the table t_user and set the current system time if the value is empty when modifying the data
#Modify the update_time column in the table t_user When modifying the data, if the value is empty, it will be set to the current system timeALTER TABLE t_user MODIFY update_time timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP COMMENT 'Update time';2.2 Add a time column to an existing table to set the default value
Add create_time column in table t_user
#Add create_time column in table t_userALTER TABLE t_user ADD create_time timestamp not null default CURRENT_TIMESTAMP COMMENT 'create time';Add update_time column in table t_user
#Add update_time column in table t_userALTER TABLE t_user ADD update_time timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP COMMENT 'Update time';2.3 Set the default value of the time column when creating a table
create table t_user(id integer not null auto_increment primary key,user_name varchar(20) not null ,update_time timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP COMMENT 'Update time',create_time timestamp default CURRENT_TIMESTAMP COMMENT 'create time');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
边栏推荐
猜你喜欢

Hospital management system database, course design, SQLserver, pure code design

FCN中制作自己的数据集并进行训练

Intranet Penetration Learning (IV) Domain Lateral Movement - SMB and WMI Service Utilization

细讲DDD领域驱动设计

mysql 索引使用与优化
![[ 图 论 ]二分图判定及其匹配(基础+提高)](/img/79/56f750e71f558debe3d99404e296e3.png)
[ 图 论 ]二分图判定及其匹配(基础+提高)

SQL study notes - REGEXP operator

KVM虚拟化作业

Android studio连接MySQL并完成简单的登录注册功能

unity-shader-2
随机推荐
线程池 ThreadPoolExecutor 详解
[ 图 论 ]二分图判定及其匹配(基础+提高)
【LeetCode】21. 合并两个有序链表
透过开发抽奖小程序,体会创新与迭代
细讲DDD领域驱动设计
darknet 训练分类网络
蓝牙协议栈开发板 STM32F1 跑蓝牙协议栈 –传统蓝牙搜索演示以及实现原理[通俗易懂]
MySQL 的 limit 分页查询及性能问题
【LeetCode】118.杨辉三角
Redis缓存面临的缓存穿透问题
SQL如何从字符串截取指定字符(LEFT、MID、RIGHT三大函数)
SQL study notes - REGEXP operator
SQL - Left join, Right join, Inner join
【云原生监控系列第一篇】一文详解Prometheus普罗米修斯监控系统(山前前后各有风景,有风无风都很自由)
pycharm汉化教程(碧蓝幻想汉化插件安装)
FCN中制作自己的数据集并进行训练
拥抱趋势!阿里这套微服务开源框架权威手册,实战到底层细致清晰
透过开发抽奖小程序,体会创新与迭代
musl Reference Manual
[Part 1 of Cloud Native Monitoring Series] A detailed explanation of Prometheus monitoring system