我有一张像
这样的表格create table test (
id int,
a int,
mtime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
);
在正常情况下,我修改记录时需要mtime自动更新。但有时我需要保持mtime不变。
这是related question。从那以后,我得到了我需要的是这句话:
update table test set a = 3, mtime = mtime;
除了 ONE CASE :更新...加入... 之外,它几乎完美无缺。例如,
UPDATE test
JOIN
(select test.id from test
JOIN middle on middle.test_id = test.id
JOIN test_2 on middle.test_2_id = test_2.id
WHERE test_2.id = 3) tmp
ON test.id = tmp.id
SET test.a = 4, test.mtime = test.mtime
它完全改变了表测试中的mtime。那么,我该怎么做呢?
-------------编辑----------- 它也不起作用:
update test
join middle on test.id = middle.test_id
join test2 on test2.id = middle.test2.id
set test.a = 3, test.mtime = test.mtime
where test2.id = test2.id + 4; -- after test, set tset2.id = 4 works,