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