---
title: "MySQL时间列自动插入当前时间"
author: "xxtianxiaxing"
date: "2009-11-03T09:48:21Z"
tags: ["MySQL", "SQL"]
slug: "mysql"
draft: false
lastmod: "2009-11-03T10:19:19Z"
id: 509058
url: "https://xylonwang.iteye.com/blog/509058"
---

```java

注意：用current_timestamp，不过这个默认值只用在timestamp的列，对datetime列无效。 
一个表只能有一个timestamp列的默认值为当前日期时间。 
SQL:
create table default_time (   
  id int not null primary key auto_increment,   
  name varchar(20) default 'chenlb',   
  my_time timestamp default current_timestamp  
);  

//或者 通过DBMS 添加列，将时间列默认值 设置为 CURRENT_TIMESTAMP，

OK，Try to insert into  





```