用current_timestamp,不过这个默认值只用在timestamp的列,对datetime列无效
例子:
create table tableName (
id int not null primary key auto_increment,
name varchar(20) default 'chenlb',
time timestamp default current_timestamp
);
注意:一个表只能有一个timestamp列的默认值为当前日期时间。
本文介绍如何使用current_timestamp为timestamp类型的数据库表字段设置默认值,并提供了一个具体的创建表的例子。
用current_timestamp,不过这个默认值只用在timestamp的列,对datetime列无效
例子:
create table tableName (
id int not null primary key auto_increment,
name varchar(20) default 'chenlb',
time timestamp default current_timestamp
);
注意:一个表只能有一个timestamp列的默认值为当前日期时间。
1万+