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字段会自动更新时间。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM