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: Can Check Constraints be Reused for Multiple Columns?

Re: Can Check Constraints be Reused for Multiple Columns?

From: Connor McDonald <connor_mcdonald_at_yahoo.com>
Date: Tue, 09 Aug 2005 22:08:04 +0800
Message-ID: <42F8B8C4.51B0@yahoo.com>


GeoPappas wrote:
>
> I have a bunch of columns that are a CHAR(1) and should only contain
> "Y" (for Yes) and "N" (for No).
>
> Instead of creating a separate check constraint for each and every
> column, is there a way to set up one check constraint and reuse it for
> multiple columns?
>
> Or is there a better way of doing this?

alter table T
  add constraint C check

     (    col1 in ('Y','N')
      and col2 in ('Y','N')
      and col3 in ('Y','N')
      and col4 in ('Y','N')
      and col5 in ('Y','N')
     )

Using a trigger will have significantly more overhead than a constraint, so I'm not sure why others are suggesting it

hth
connor

-- 
Connor McDonald
Co-author: "Mastering Oracle PL/SQL - Practical Solutions"
Co-author: "Oracle Insight - Tales of the OakTable"

web: http://www.oracledba.co.uk
web: http://www.oaktable.net
email: connor_mcdonald_at_yahoo.com


"Semper in excremento, sole profundum qui variat."

------------------------------------------------------------
Received on Tue Aug 09 2005 - 09:08:04 CDT

Original text of this message

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