timestamp类型的使用示例如下:
1,创建一个数据库,并指定 uptime为 timestamp类型
create table test(
tid int primary key auto_increment,
uptime timestamp,
hobby varchar(20)
);
2.插入一条数据
insert into test (tid,uptime,hobby) values(null,null,null);
3.查看数据库数据
我们看到数据插入成功,但是uptime字段显示为 null。
4.我们再插入一条数据,如下:
insert into test (tid,uptime,hobby) values(null,current_timestamp,null);
查看数据库数据,我们看到第二条数据插入成功了,并且时间为 当前插入的时间
5,下面我们更新一下字段看 时间是否会自动维护
update test set hobby='篮球' where tid < 4;
我们看效果,发现时间并没有自动更新,还是我们插入的时间,并不是修改的时间。
6.我们首先手动更新一下时间:
update test set uptime = current_timestamp where tid < 10;
成功。
作者:采购
原文:https://3pomelos.1688.com/
版权声明:本文为转载文章
转载于:https://blog.51cto.com/14127231/2333887