MySQL表内更新时,自动记录时间

1.创建表:

create table test_time
(
id int primary key not null,
status  varchar(24),
create_time datetime default current_timestamp,
update_time datetime default current_timestamp on update current_timestamp
);
alter table test_time comment='测试时间表';

2.插入数据:

insert into test_time values(1,'ok',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP);

3.更新状态:

update  test_time set status = 'no';

4.查看:

 结论: 插入的时候,时间一致,有更新时,字段update_time字段会自动更新时间。

原文地址:https://www.cnblogs.com/hello-wei/p/10600239.html