python學習筆記 day43 創建時間與更新時間(自動)


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM