---
title: "mysql 时间列自动插入当前日期时间 "
author: "junjun19860702"
date: "2012-05-09T13:46:08Z"
tags: []
categories: ["数据库"]
slug: "mysql"
draft: false
lastmod: "2012-05-09T13:46:08Z"
id: 1518731
url: "https://jun1986.iteye.com/blog/1518731"
---

用current\_timestamp，不过这个默认值只用在timestamp的列，对datetime列无效

例子：

create table default\_time (  
id int not null primary key auto\_increment,  
name varchar(20) default 'chenlb',  
my\_time timestamp default current\_timestamp  
);

注意：一个表只能有一个timestamp列的默认值为当前日期时间。

 

例子：

insert into TB\_IOT\_SERVERCHILD(ParentID,ChildName,StartPath,logPath,Remark ,isStop ,isVisible,CreateTime) values(1,'子服务gggggggg','','','',0,0,current\_timestamp)