Subject | Transactions and triggers |
---|---|
Author | lobolo2000 |
Post date | 2006-09-13T13:29:19Z |
The SQL below guarantees uniqueness of F1 union F2 within a single
transaction. Can this concept be extended to cover 2 simultaneous
transactions that add records to these tables then commit one after
the other?
CREATE TABLE1 (
PK BIGINT PRIMARY KEY,
F1 INTEGER UNIQUE):
CREATE TABLE2 (
PK BIGINT PRIMARY KEY,
F2 INTEGER UNIQUE):
CREATE TRIGGER TRIGGER1 FOR TABLE1 BEFORE INSERT OR UPDATE POSITION 0
AS BEGIN
IF (EXISTS(SELECT F2 FROM TABLE2 WHERE F2=NEW.F1)) THEN EXCEPTION
DUPLICATE_FIELD;
END
CREATE TRIGGER TRIGGER2 FOR TABLE2 BEFORE INSERT OR UPDATE POSITION 0
AS BEGIN
IF (EXISTS(SELECT F1 FROM TABLE1 WHERE F1=NEW.F2)) THEN EXCEPTION
DUPLICATE_FIELD;
END
transaction. Can this concept be extended to cover 2 simultaneous
transactions that add records to these tables then commit one after
the other?
CREATE TABLE1 (
PK BIGINT PRIMARY KEY,
F1 INTEGER UNIQUE):
CREATE TABLE2 (
PK BIGINT PRIMARY KEY,
F2 INTEGER UNIQUE):
CREATE TRIGGER TRIGGER1 FOR TABLE1 BEFORE INSERT OR UPDATE POSITION 0
AS BEGIN
IF (EXISTS(SELECT F2 FROM TABLE2 WHERE F2=NEW.F1)) THEN EXCEPTION
DUPLICATE_FIELD;
END
CREATE TRIGGER TRIGGER2 FOR TABLE2 BEFORE INSERT OR UPDATE POSITION 0
AS BEGIN
IF (EXISTS(SELECT F1 FROM TABLE1 WHERE F1=NEW.F2)) THEN EXCEPTION
DUPLICATE_FIELD;
END