当前位置:Gxlcms > 数据库问题 > Mysql中设置默认时间为当前值

Mysql中设置默认时间为当前值

时间:2021-07-01 10:21:17 帮助过:2人阅读

TABLE `table1` ( `id` int(11) NOT NULL, `createtime` timestamp NULL default 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

 

  

  

 

Mysql中设置默认时间为当前值

标签:

人气教程排行