MIDRANGE dot COM Mailing List Archive



Home » MIDRANGE-L » May 2010

Re: Can I have check and referential constraint on same column?



fixed

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


On Thu, May 20, 2010 at 1:35 PM, <Rick.Chevalier@xxxxxxxxxxxxxxx> wrote:

That's the impression I got from the documentation. It didn't explicitly
say it couldn't be done, but I was wondering how it would work. If a value
passes one constraint but fails another is the record added or not? I'm
about to give it a try.

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

AFAIK, yes.

Regards,

Luis Rodriguez
IBM Certified Systems Expert - eServer i5 iSeries


On Thu, May 20, 2010 at 11:22 AM, <Rick.Chevalier@xxxxxxxxxxxxxxx> wrote:

I have come across a situation where I think I need both a check
constraint and a referential constraint on the same column to handle
different situations.

When a row is inserted the default value for the status column will be
'N'.
When the information has been validated it will change to 'V'. This
is my current check constraint.

If the validation is overridden an override code can be placed into
the status column from an exception table. This is my referential
constraint.

I have thought about adding the check values to the exception table
and excluding them from the exception prompt but I would prefer to
handle it without doing that if possible. If I can't have both
constraints on the status column this is probably what I will do.


Rick Chevalier
IT Software Solutions - Loan Servicing



________________________________
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.


--
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.



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.







Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2014 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