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: Tony Andrews <andrewst_at_onetel.com>
Date: 11 Aug 2005 04:32:21 -0700
Message-ID: <1123759941.475350.239450@g49g2000cwa.googlegroups.com>


xhoster_at_gmail.com wrote:
> "GeoPappas" <PappasG_at_gmail.com> 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?
>
> Why? Do you think that Oracle has a finite bag of check constraints and
> that it might run out?

:) Amusing answer, but it rather suggests that just because Oracle doesn't offer something, it would not be useful. "Code reuse" is generally considered a Good Thing, so why not with constraints? As someone else said earlier, this would be provided if Oracle supported domains so that instead of...

CREATE TABLE T

( col1 VARCHAR(1) CHECK (col1 IN ('Y','N'))
, col2 VARCHAR(1) CHECK (col2 IN ('Y','N'))
, col3 VARCHAR(1) CHECK (col3 IN ('Y','N'))
...
, col99 VARCHAR(1) CHECK (col99 IN ('Y','N')) );

... you could do this:

CREATE TABLE T
( col1 yn
, col2 yn
, col3 yn
...
, col99 yn
);

That would be cool, would it not? Received on Thu Aug 11 2005 - 06:32:21 CDT

Original text of this message

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