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

 

posted @ 2018-10-29 16:29  写的BUG代码少  阅读(1602)  评论(0编辑  收藏  举报