如SHOW TABLE STATUS
语法中所述:
相反,您可以创建触发器,在修改表时使用当前时间戳更新单独的表:
CREATE TABLE log (
table_name VARCHAR(64) NOT NULL,
lastmodified TIMESTAMP NOT NULL,
PRIMARY KEY (table_name)
);
CREATE TRIGGER foo_ins AFTER INSERT ON my_table FOR EACH ROW
INSERT INTO log (table_name, lastmodified) VALUES ('my_table', NOW())
ON DUPLICATE KEY UPDATE lastmodified = NOW();
CREATE TRIGGER foo_ins AFTER UPDATE ON my_table FOR EACH ROW
INSERT INTO log (table_name, lastmodified) VALUES ('my_table', NOW())
ON DUPLICATE KEY UPDATE lastmodified = NOW();
CREATE TRIGGER foo_ins AFTER DELETE ON my_table FOR EACH ROW
INSERT INTO log (table_name, lastmodified) VALUES ('my_table', NOW())
ON DUPLICATE KEY UPDATE lastmodified = NOW();