dbTalk Databases Forums  

Using a trigger to enforce unique if not null DB2 v8.1.9 linux

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss Using a trigger to enforce unique if not null DB2 v8.1.9 linux in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Bob Stearns
 
Posts: n/a

Default Using a trigger to enforce unique if not null DB2 v8.1.9 linux - 05-26-2006 , 01:59 AM






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,regnum 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.assoc OR
n.prefix<>o.prefix OR
n.regnum<>o.regnum)
OR
o.regnum='')))
SIGNAL SQLSTATE '75103'
SET MESSAGE_TEXT='Duplicate assoc/prefix/regnum'
GO

Reply With Quote
  #2  
Old   
Konstantin Andreev
 
Posts: n/a

Default Re: Using a trigger to enforce unique if not null DB2 v8.1.9 linux - 05-26-2006 , 11:21 AM






Please, provide the script to demonstrate your issue. Your design isn't
clear.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.