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.
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?
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...
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,
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
This mailing list archive is Copyright 1997-2015 by MIDRANGE dot 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 here. If you have questions about this, please contact