× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



The way we do it is define single-column check constraints right with the
column definition. These do not require naming.
As for multi-column check constraints, we sometimes name them but more often
than not we let the system generate a unique name for it. If you omit the
name, system will generate one for you.

Here is a sample create table.

CREATE TABLE XCEXCLUDE
(
ACTIONTYPE CHAR (10) NOT NULL WITH DEFAULT
CHECK(ACTIONTYPE IN ('*AUTOINDEX',
'*UNUSEDIDX',
'*SOINDEX ',
'*DUPEINDEX',
'*FOURGBIDX',
'*PGSZINDEX',
'*RGZINDEX ',
'*FRCINDEX ',
'*CRTINDEX '
)),
LIBRARY CHAR (10) NOT NULL WITH DEFAULT,
OBJECT CHAR (10) NOT NULL WITH DEFAULT
CHECK(OBJECT = '*ALL' OR SUBSTR(OBJECT,1,1) <> '*'),
STAGE CHAR ( 1) NOT NULL WITH DEFAULT
CHECK(STAGE IN ('D','A')),
FILTER CHAR ( 1) NOT NULL WITH DEFAULT

CHECK(FILTER IN ('E','I')),

PRIMARY KEY (ACTIONTYPE,LIBRARY,OBJECT,STAGE),

CONSTRAINT NO_SPECIAL_EXCLUDE

CHECK((FILTER = 'I' AND STAGE = 'D' AND ACTIONTYPE = '*AUTOINDEX') OR

(FILTER = 'I' AND STAGE = 'A' AND ACTIONTYPE <> '*AUTOINDEX' AND

(LIBRARY = '*ALL' OR SUBSTR(LIBRARY,1,1) <> '*')) OR

(FILTER = 'E' AND ACTIONTYPE <> '*AUTOINDEX' AND

((STAGE = 'A' AND LIBRARY = '*ALL') OR SUBSTR(LIBRARY,1,1) <>
'*')))


);

Hope that helps.

Elvis

Mike Cain - DB2 for i5/OS Temporary Indexes - The Good, The Bad, The Ugly
October 16
2007 System i Fall Technical Conference | Orlando | November 4-7
Celebrating 10-Years of SQL Performance Excellence on IBM System i, eServer
iSeries and the server affectionately known as the AS/400

-----Original Message-----
Subject: Check Constraints - proper use of

Hi everyone,

If I understand correctly, people are advising to put as much validation
in the table as possible. This includes Key Constraints, Foreign Key
Constraints, and Check Constraints.

My question is two-fold:

If I want to create a table that has 20 fields, and all of the columns are
required to have data, does this mean I should have 20 check constraints,
testing for <> ' ' or <> 0 for char and dec?

The second part of my question is in regards to the naming of Check
Constraints.

Since constraints must be unique in the schema for which the table
resides, how are people naming their constraints? i.e. are people putting
the file and field names in the constraint name? e.g.

CONSTRAINT GLENN."FileABC Primary Key" PRIMARY KEY (CHARFIELD1)
CONSTRAINT GLENN."FileABC CharField1 Mandatory" CHECK ( CHARFIELD1 <> ' ')
CONSTRAINT GLENN."FileABC CharField2 Mandatory" CHECK ( DECFIELD2 <> 0)
CONSTRAINT GLENN."FileABC CharField3 Mandatory" CHECK ( CHARFIELD3 <> ' ')

Thank you.

Glenn Gundermann



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.