On 8/18/17, Wout Mertens <[email protected]> wrote: > > So, bottom line, is there a way to insert or replace a row so that first > the id constraint is observed (replacing a previous row with the same id), > and then the k constraint is verified (failing to replace if k is already > present in the table)?
CREATE TABLE demo(id INTEGER PRIMARY KEY, k TEXT, otherstuff ANY); CREATE INDEX demo_k ON demo(k); CREATE TRIGGER demo_trigger1 BEFORE INSERT ON demo BEGIN SELECT raise(ABORT,'uniqueness constraint failed on k') FROM demo WHERE k=new.k; END; The above will force uniqueness on k for INSERT statements. You'll want a second "BEFORE UPDATE" trigger to do similar enforcement for UPDATEs if that is an issue for you. -- D. Richard Hipp [email protected] _______________________________________________ sqlite-users mailing list [email protected] http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

