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