当前位置:网站首页>mysql 时间字段默认设置为当前时间
mysql 时间字段默认设置为当前时间
2022-07-30 05:31:00 【嗯嗯好的呢!】
1、直接在创建表时添加该列并声明默认值,如下:
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;
如果是在navicat下操作的话,设置字段的类型为timestamp,默认值写上CURRENT_TIMESTAMP,如下图:

2、在现有表中添加新列
ALTER TABLE table1
ADD COLUMN `createtime` timestamp NULL DEFAULT CURRENT_TIMESTAMP
3、 修改某一列为时间格式并添加默认值
alter table table1
change createtime newtime timestamp null default current_timestamp
4、展示毫秒
如果想记录到毫秒,设置CURRENT_TIMESTAMP(3)即可
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
猜你喜欢

丑陋的程序员

I went to meet some successful people worth tens of millions on May 1st, and I have some new ideas and inspirations

路径依赖:穷人很难逆袭突破的科学道理

cmd(命令行)操作或连接mysql数据库,以及创建数据库与表

It's time to have to learn English, give yourself multiple paths

This article will take you through js to deal with the addition, deletion, modification and inspection of tree structure data

MySQL - Function and Constraint Commands

postman 请求 post 调用 传 复合 json数据

go版本升级

WeChat payment and payment callback
随机推荐
MySQL安装配置教程(超级详细)
最新版MySQL 8.0 的下载与安装(详细教程)
MySQL stored procedure
MySql string splitting realizes the split function (field splitting, column switching, row switching)
MySQL - 函数及约束命令
2022 Pengcheng Cup web
[Mysql] DATEDIFF函数
Docker-compose安装mysql
力扣05-替换空格——字符串问题
路径依赖:穷人很难逆袭突破的科学道理
号称年薪30万占比最多的专业,你知道是啥嘛?
【Koltin Flow(一)】五种创建flow的方式
MySQL-Explain详解
JVM 垃圾回收 超详细学习笔记(二)
MySQL - Function and Constraint Commands
倒计数(来源:Google Kickstart2020 Round C Problem A)(DAY 88)
Personal blog system (with source code)
[GLib] 什么是GType
curl (7) Failed connect to localhost8080; Connection refused
idea 编译protobuf 文件的设置使用