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: CUSTOM data integrity constraint

Re: CUSTOM data integrity constraint

From: PaulCinVT <paulcinvt_at_aol.com>
Date: 24 Aug 1999 18:17:39 GMT
Message-ID: <19990824141739.01753.00001863@ngol08.aol.com>


>>There are two fields in a table which are of datatype varchar2.
Say Field1, Field2.
When Field1 is NON NULL, Field2 CAN'T be NULL. How could i impose this as a constraint to one of the fields? <<

>...
I think this is achievable with INSERT trigger. --
Nandakumar
(N.Kumar_at_rocketmail.com)
<

Just use a check constraint on the table:

CHECK ((Field1 IS NULL AND Field2 IS NULL) OR (Field1 IS NOT NULL AND Field2 IS NOT NULL)

As an aside:

According to the ANSI/ISO standard, a NOT NULL integrity constraint is an example of a CHECK integrity constraint, where the condition is

CHECK (column_name IS NOT NULL)

Therefore, NOT NULL integrity constraints for a single column can, in practice, be written in two forms: using the NOT NULL constraint or a CHECK constraint. For ease of use, you should always choose to define NOT NULL integrity constraints instead of CHECK constraints with the "IS NOT NULL" condition.

Paul in VT Received on Tue Aug 24 1999 - 13:17:39 CDT

Original text of this message

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