I have successfully designed a trigger to make sure a set of fields are
unique if not null. However it fails in one case: when the duplication
occurs among a set of rows being updated simultaneously. The trigger is
below. Can you suggest a way to improve it to eliminate the failure? I
don't know enough about triggers to know if changing BEFORE UPDATE to
AFTER UPDATE, for instance, might do what I want. This is only my 5th
trigger.
BTW: Is the column list in the OF phrase an 'or' or an 'and' between the
columns?
CREATE TRIGGER IS3.AN_apr_UNQ_ U
NO CASCADE BEFORE UPDATE OF assoc,prefix,re gnum ON is3.animals
REFERENCING NEW AS N OLD AS O
FOR EACH ROW MODE DB2SQL
WHEN (n.regnum<>''
AND EXISTS(SELECT * FROM is3.animals
WHERE assoc=N.assoc
AND prefix=n.prefix
AND regnum=n.regnum
AND ((n.assoc<>o.as soc OR
n.prefix<>o.pre fix OR
n.regnum<>o.reg num)
OR
o.regnum='')))
SIGNAL SQLSTATE '75103'
SET MESSAGE_TEXT='D uplicate assoc/prefix/regnum'
GO