如果磁盘空间比需要这个问题更小,并且您还想在恶意 UPDATE 命令后恢复,您可以做的是创建触发器以将所有后续更改从原始表保存到单独的表中。但是请注意,这将在您的表中保存每个修订的条目。
它看起来像这样:
CREATE TABLE rev_users
(
id INTEGER NOT NULL,
username VARCHAR(45),
picLink VARCHAR(45),
revId INTEGER NOT NULL AUTO_INCREMENT,
action CHAR(6) NOT NULL,
PRIMARY KEY(revId)
);
CREATE TRIGGER rev_users_i AFTER INSERT ON users FOR EACH ROW BEGIN
INSERT INTO rev_users (id, username, picLink, action)
VALUES (NEW.id, NEW.username, NEW.picLink, 'INSERT');
END;
CREATE TRIGGER rev_users_u AFTER UPDATE ON users FOR EACH ROW BEGIN
INSERT INTO rev_users (id, username, picLink, action)
VALUES (NEW.id, NEW.username, NEW.picLink, 'UPDATE');
END;
CREATE TRIGGER rev_users_d BEFORE DELETE ON users FOR EACH ROW BEGIN
INSERT INTO rev_users (id, username, picLink, action)
VALUES (OLD.id, OLD.username, OLD.picLink, 'DELETE');
END;