当与“INSERT OR REPLACE”触发器和唯一约束一起使用时,“UPDATE OR ROLLBACK”产生的结果与“UPDATE”不同

时间:2016-10-26 09:21:17

标签: sqlite

我正在使用 sqlite3 版本3.8.8.3,我想知道以下问题是否会导致预期结果:

BEGIN TRANSACTION;
CREATE TABLE ta (
 a integer(10) NOT NULL,
 id integer NOT NULL PRIMARY KEY );
INSERT INTO "ta" VALUES(1,1);
INSERT INTO "ta" VALUES(2,2);
INSERT INTO "ta" VALUES(3,3);
CREATE TABLE tb (
 a integer(10) NOT NULL,
CONSTRAINT c
    UNIQUE (a) );
INSERT INTO "tb" VALUES(2);
INSERT INTO "tb" VALUES(1);
CREATE TRIGGER t AFTER UPDATE ON ta
 FOR EACH ROW WHEN (old.a != new.a )
BEGIN INSERT OR REPLACE INTO tb(a) SELECT new.a; END;
COMMIT;

update or rollback ta set a=3;

- >错误:UNIQUE约束失败:tb.a

0 个答案:

没有答案