1. datetime---需要自己手动输入时间(当然也可以设置默认值)
create table info( id int not null primary key, name varchar(50) not null , time datetime not NULL default "2017-10-01" ) insert into info values(1,"xuanxuan","2017-10-10") insert into info(id,name) values(2,"xixi") select * from info;
运行结果:
2. 创建时间creat_time 更新时间update_time (自动记录数据项创建时间以及修改时间)
create table info2( id int not null auto_increment primary key, name varchar(50) not null, create_time timestamp not null default current_timestamp, update_time timestamp not null default current_timestamp on update CURRENT_TIMESTAMP ) insert into info2(id,name) values(1,"xuanxuan"),(2,"璇璇") select * from info2; update info2 set name="西西" where id=1; select * from info2;
运行结果:
参考自:
https://blog.csdn.net/wild46cat/article/details/56843595
https://blog.csdn.net/sinat_26918145/article/details/52765283?utm_source=blogxgwz1