业务需求精确到毫秒的数据最新更新时间做判断。
方案一:提供精确到毫秒的整数型时间戳
SELECT (unix_timestamp(current_timestamp(3))*1000);
alter table tb_workorderinfo add column LastUpdateTimeStamp timestamp(3) not null default (unix_timestamp(current_timestamp(3))*1000) comment '最近更新时间',
add key `NON-LastUpdateTimeStamp`(LastUpdateTimeStamp);
试图通过on update 函数对字段进行实时更新,但是失败,选择用触发器对时间戳进行更新:
delimiter $$
CREATE TRIGGER `LastUpdateTimeStamp` BEFORE UPDATE ON `tb_workorderinfo_test` FOR EACH ROW
begin
set new.LastUpdateTimeStamp = (unix_timestamp(current_timestamp(3))*1000) ;
end
$$
过程中出现报错两次:
1、 [HY000][1442] Can't update table 'tb_workorderinfo_test' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
错误写法:不应该在更新同一张表时使用update语句&#