the blank could be handled if instead of blank you allowed NULLs

That wouldn't help with the V however.

You could handle both V and blank with a before trigger

HTH,
Charles


On Thu, May 20, 2010 at 3:40 PM, <Rick.Chevalier@xxxxxxxxxxxxxxx> wrote:
I can add the constraints but it doesn't do what I need it to.  I have a check constraint of 'V' or blank and a referential constraint of 'P' or 'H' (more to come later).  The 'V' and blank are hard coded into the program depending on certain conditions.  If the user chooses an override the 'P' or 'H' will be used.  Unfortunately they appear to be mutually exclusive.

I tried inserting a row using SQL and if I use one of the referential constraint values the insert fails due to the check constraint.  If I use one of the check constraint values the insert fails due to the referential constraint.  The value has to satisfy both constraints.

It makes sense, it just doesn't work for me in this case.

Rick

-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Luis Rodriguez
Sent: Thursday, May 20, 2010 1:49 PM
To: Midrange Systems Technical Discussion
Subject: Re: Can I have check and referential constraint on same column?

Rick,

To check my answer I did a small test:

ALTER TABLE MyLib/File1
 ADD Constraint FK_CardType
     FOREIGN KEY (CardType)
     REFERENCES  MyLib/File2 (CardType) ;

ALTER TABLE File1 ADD CHECK (CardType <> 9 ) ;

No problem in creating both constraints. Even if there is a CARDTYPE 9 in File2, I can't insert a CARDTYPE 9 record in File1. The system returns CPF502F (Check constraint violation).

Did not check what happens the CHECK constraint is created before the foreign key...

HTH,
Luis Rodriguez
IBM Certified Systems Expert - eServer i5 iSeries

Privileged and Confidential.  This e-mail, and any attachments there to, is intended only for use by the addressee(s) named herein and may contain privileged or confidential information.  If you have received this e-mail in error, please notify me immediately by a return e-mail and delete this e-mail.  You are hereby notified that any dissemination, distribution or copying of this e-mail and/or any attachments thereto, is strictly prohibited.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.