Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Insert trigger to enforce uniqueness

Re: Insert trigger to enforce uniqueness

From: Thomas Kyte <tkyte_at_oracle.com>
Date: 3 Mar 2002 18:10:05 -0800
Message-ID: <a5ul1t02kjr@drn.newsguy.com>


In article <26ee1067.0203031743.c3da536_at_posting.google.com>, tram_e_at_hotmail.com says...
>
>Hi,
>
>Our third party application doesn't allow to create Unique indexes on
>a column.
>I want to write an insert trigger which allow nulls but no duplicate
>values on a column (peopleID column). Waht is the best way to write
>BEFORE INSERT TRIGGER for thsi kind of requirement? Please give sample

just create a unique constraint on it and be done with it. No worse for you to create a unique index then to add triggers to third party products (no better either)

It will allow NULLS and enforce uniqueness. Doing this in a trigger is fruitless unless you serialize all inserts into this table (multi-versioning, if two people insert to same value at the same time -- your trigger will never see it).

--
Thomas Kyte (tkyte@us.oracle.com)             http://asktom.oracle.com/ 
Expert one on one Oracle, programming techniques and solutions for Oracle.
http://www.amazon.com/exec/obidos/ASIN/1861004826/  
Opinions are mine and do not necessarily reflect those of Oracle Corp 
Received on Sun Mar 03 2002 - 20:10:05 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US