ibm-information-center/dist/eclipse/plugins/i5OS.ic.cl_5.4.0.1/addpfcst.htm

474 lines
20 KiB
HTML
Raw Permalink Normal View History

2024-04-02 14:02:31 +00:00
<!doctype html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><META http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Add PF Constraint (ADDPFCST)</title>
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
</head>
<body bgcolor="white">
<script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<a name="ADDPFCST.Top_Of_Page"></a>
<h2>Add PF Constraint (ADDPFCST)</h2>
<table width="100%">
<tr>
<td valign="top" align="left"><b>Where allowed to run: </b>All environments (*ALL)<br>
<b>Threadsafe: </b>Conditional
</td>
<td valign="top" align="right">
<a href="#ADDPFCST.PARAMETERS.TABLE">Parameters</a><br>
<a href="#ADDPFCST.COMMAND.EXAMPLES">Examples</a><br>
<a href="#ADDPFCST.ERROR.MESSAGES">Error messages</a></td>
</tr>
</table>
<div> <a name="ADDPFCST"></a>
<p>The Add Physical File Constraint (ADDPFCST) command can be used to add constraint relationships to a specified physical file. The four types of constraint relationships that you can add are referential constraints, unique constraints, primary key constraints and check constraints. All constraints are defined at the file level.
</p>
<p>You can use constraint relationships to define dependencies between files. The relationships that you define are enforced by the system when changes occur to information in the files. When you define constraint relationships you control the <b>referential integrity</b> of the data being processed.
</p>
<p>To define or establish a referential constraint, the parent file and the dependent file must exist. However, if the parent or dependent file has no members, the constraint only is defined (not established).
</p>
<p>When a referential constraint is established, either an access path is created or an existing access path with matching attributes is shared. A maximum of 300 constraint relationships can be established for a file. However, only one primary key constraint can be established for a file.
</p>
<p>You can remove a constraint by using the Remove Physical File Constraint (RMVPFCST) command. You can view all constraints for a dependent file by using the Display File Description (DSPFD) command.
</p>
<p><b>Restrictions:</b>
</p>
<ul>
<li>You cannot add constraint relationships to system files or to program described files.
</li>
<li>You cannot add a constraint relationship to a file that your user job has open.
</li>
<li>Referential constraints cannot span auxiliary storage pools (ASPs).
</li>
<li>Constraints cannot be added to a file in the temporary library QTEMP.
</li>
<li>If a check or referential constraint is added with this command and the established referential or check constraint has records that are in check pending, the constraint is automatically changed to the disabled state.
</li>
<li>This command is conditionally threadsafe. In multithreaded jobs, this command is not threadsafe for distributed files and fails for distributed files that use relational databases of type *SNA.
</li>
</ul>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFCST.Top_Of_Page">Top</a></td></tr>
</table>
<hr size="2" width="100%">
<div>
<h3><a name="ADDPFCST.PARAMETERS.TABLE">Parameters</a></h3>
<table border="1" cellpadding="4" cellspacing="0">
<!-- col1="10" col2="15" col3="30" col4="10" -->
<tr>
<th bgcolor="aqua" valign="bottom" align="left">Keyword</th>
<th bgcolor="aqua" valign="bottom" align="left">Description</th>
<th bgcolor="aqua" valign="bottom" align="left">Choices</th>
<th bgcolor="aqua" valign="bottom" align="left">Notes</th>
</tr>
<tr>
<td valign="top" rowspan="3"><a href="#ADDPFCST.FILE"><b>FILE</b></a></td>
<td valign="top">File</td>
<td valign="top"><i>Qualified object name</i></td>
<td valign="top" rowspan="3">Required, Positional 1</td>
</tr>
<tr>
<td valign="top">Qualifier 1: File</td>
<td valign="top"><i>Name</i></td>
</tr><tr>
<td valign="top">Qualifier 2: Library</td>
<td valign="top"><i>Name</i>, <b><u>*LIBL</u></b>, *CURLIB</td>
</tr><tr>
<td valign="top"><a href="#ADDPFCST.TYPE"><b>TYPE</b></a></td>
<td valign="top">Constraint type</td>
<td valign="top">*REFCST, *UNQCST, *PRIKEY, *CHKCST</td>
<td valign="top">Required, Positional 2</td>
</tr>
<tr>
<td valign="top"><a href="#ADDPFCST.KEY"><b>KEY</b></a></td>
<td valign="top">Constraint key</td>
<td valign="top">Values (up to 120 repetitions): <i>Name</i></td>
<td valign="top">Optional, Positional 3</td>
</tr>
<tr>
<td valign="top"><a href="#ADDPFCST.CST"><b>CST</b></a></td>
<td valign="top">Constraint name</td>
<td valign="top"><i>Character value</i>, <b><u>*GEN</u></b></td>
<td valign="top">Optional</td>
</tr>
<tr>
<td valign="top" rowspan="3"><a href="#ADDPFCST.PRNFILE"><b>PRNFILE</b></a></td>
<td valign="top">Parent file</td>
<td valign="top"><i>Qualified object name</i></td>
<td valign="top" rowspan="3">Optional</td>
</tr>
<tr>
<td valign="top">Qualifier 1: Parent file</td>
<td valign="top"><i>Name</i></td>
</tr><tr>
<td valign="top">Qualifier 2: Library</td>
<td valign="top"><i>Name</i>, <b><u>*LIBL</u></b>, *CURLIB</td>
</tr><tr>
<td valign="top"><a href="#ADDPFCST.PRNKEY"><b>PRNKEY</b></a></td>
<td valign="top">Parent key</td>
<td valign="top">Single values: <b><u>*PRNFILE</u></b><br>Other values (up to 120 repetitions): <i>Name</i></td>
<td valign="top">Optional</td>
</tr>
<tr>
<td valign="top"><a href="#ADDPFCST.DLTRULE"><b>DLTRULE</b></a></td>
<td valign="top">Delete rule</td>
<td valign="top">*CASCADE, <b><u>*NOACTION</u></b>, *SETDFT, *SETNULL, *RESTRICT</td>
<td valign="top">Optional</td>
</tr>
<tr>
<td valign="top"><a href="#ADDPFCST.UPDRULE"><b>UPDRULE</b></a></td>
<td valign="top">Update rule</td>
<td valign="top"><b><u>*NOACTION</u></b>, *RESTRICT</td>
<td valign="top">Optional</td>
</tr>
<tr>
<td valign="top"><a href="#ADDPFCST.CHKCST"><b>CHKCST</b></a></td>
<td valign="top">Check constraint</td>
<td valign="top"><i>Character value</i></td>
<td valign="top">Optional</td>
</tr>
</table>
<table width="100%">
<tr><td align="right"><a href="#ADDPFCST.Top_Of_Page">Top</a></td></tr>
</table>
</div>
<div> <a name="ADDPFCST.FILE"></a>
<h3>File (FILE)</h3>
<p>Specifies the file to which a constraint is being added. The file must be a physical file and it must allow a maximum of one member (MAXMBRS(1)).
</p>
<p>If a referential constraint is being added, this parameter specifies the dependent file and the library containing the dependent file. The parent file is specified on the PRNFILE parameter.
</p>
<p>This is a required parameter.
</p>
<p><b>Qualifier 1: File</b>
</p>
<dl>
<dt><b><i>name</i></b></dt>
<dd>Specify the name of the physical file.
</dd>
</dl>
<p><b>Qualifier 2: Library</b>
</p>
<dl>
<dt><b><u>*LIBL</u></b></dt>
<dd>All libraries in the library list for the current thread are searched until the first match is found.
</dd>
</dl>
<dl>
<dt><b>*CURLIB</b></dt>
<dd>The current library for the job is searched. If no library is specified as the current library for the job, the QGPL library is used.
</dd>
<dt><b><i>name</i></b></dt>
<dd>Specify the name of the library to be searched.
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFCST.Top_Of_Page">Top</a></td></tr>
</table>
<div> <a name="ADDPFCST.TYPE"></a>
<h3>Constraint type (TYPE)</h3>
<p>Specifies the type of constraint being added to the physical file.
</p>
<p>This is a required parameter.
</p>
<dl>
<dt><b>*REFCST</b></dt>
<dd>A referential constraint is being added.
<p><b>Notes:</b>
</p>
<ul>
<li>Referential constraints cannot span multiple ASPs (auxiliary storage pools).
</li>
<li>Referential constraints cannot be added while either the parent or the dependent file is open.
</li>
<li>Duplicate and multiple referential constraints can be added between the same dependent and parent files if the constraint name is unique. However, the results may not match your expectations. See the Database information in the iSeries Information Center at http://www.ibm.com/eserver/iseries/infocenter for advisory information on duplicate or multiple referential constraints.
</li>
</ul>
</dd>
<dt><b>*UNQCST</b></dt>
<dd>A unique constraint is being added.
<p>
<b>Note: </b>Duplicate unique constraints are not allowed.
</p>
</dd>
<dt><b>*PRIKEY</b></dt>
<dd>A primary key constraint is being added. A primary key constraint is a special case of a unique constraint.
<p>
<b>Note: </b>Only one primary key constraint is allowed per physical file.
</p>
</dd>
<dt><b>*CHKCST</b></dt>
<dd>A check constraint is being added.
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFCST.Top_Of_Page">Top</a></td></tr>
</table>
<div> <a name="ADDPFCST.KEY"></a>
<h3>Constraint key (KEY)</h3>
<p>Specifies the constraint key, which is the definition of the access path for the type of constraint specified on the TYPE parameter. The constraint key is one or more fields that exist in the file specified on the file parameter. For referential and unique constraints, the fields specified can allow nulls (ALWNULL). For primary key constraints, the fields specified cannot allow nulls.
</p>
<dl>
<dt><b>*REFCST</b></dt>
<dd>The foreign key of a referential constraint is defined. If a referential constraint is established, a foreign key access path is added to the dependent file.
</dd>
<dt><b>*UNQCST</b></dt>
<dd>The key of a unique constraint is defined. If a unique constraint is established, a unique key access path is added to the physical file.
</dd>
<dt><b>*PRIKEY</b></dt>
<dd>The key of a primary key constraint is defined. If a primary key constraint is established, a primary key access path is added to the physical file.
</dd>
<dt><b>*CHKCST</b></dt>
<dd>The constraint key (KEY) parameter does not apply for check constraints. Check constraints use the CHKCST parameter to specify a check constraint expression.
</dd>
</dl>
<dl>
<dt><b><i>name</i></b></dt>
<dd>Specify the name of the field for the constraint key you are defining. Each field name must exist in the file specified on the FILE parameter. You can specify a maximum of 120 (but no duplicate) field names to define the constraint key, where:
<ul>
<li>The field names are of the object type *NAME and are a maximum length of 10.
</li>
<li>The fields must be specified in ascending order.
</li>
<li>The maximum number of bytes in a key is 32768 bytes (see the Database information in the iSeries Information Center at http://www.ibm.com/eserver/iseries/infocenter for more information on this limitation).
</li>
</ul>
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFCST.Top_Of_Page">Top</a></td></tr>
</table>
<div> <a name="ADDPFCST.CST"></a>
<h3>Constraint name (CST)</h3>
<p>Specifies the name of the constraint being added.
</p>
<dl>
<dt><b><u>*GEN</u></b></dt>
<dd>The system generates a constraint name.
</dd>
<dt><b><i>character-value</i></b></dt>
<dd>Specify the name of the constraint. The constraint name must be unique to the library of the physical file specified on the FILE parameter. You can specify a maximum of 128 characters without delimiters, or 258 characters with quotation mark (") delimiters.
<p>
<b>Note: </b>The case is preserved when lowercase characters are specified.
</p>
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFCST.Top_Of_Page">Top</a></td></tr>
</table>
<div> <a name="ADDPFCST.PRNFILE"></a>
<h3>Parent file (PRNFILE)</h3>
<p>Specifies the parent file of a referential constraint. The file must be a physical file and it must allow a maximum of one member (MAXMBRS(1)).
</p>
<p><b>Qualifier 1: Parent file</b>
</p>
<dl>
<dt><b><i>name</i></b></dt>
<dd>Specify the name of the parent file of a referential constraint.
</dd>
</dl>
<p><b>Qualifier 2: Library</b>
</p>
<dl>
<dt><b><u>*LIBL</u></b></dt>
<dd>All libraries in the library list for the current thread are searched until the first match is found.
</dd>
</dl>
<dl>
<dt><b>*CURLIB</b></dt>
<dd>The current library for the job is searched. If no library is specified as the current library for the job, the QGPL library is used.
</dd>
<dt><b><i>name</i></b></dt>
<dd>Specify the name of the library to be searched.
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFCST.Top_Of_Page">Top</a></td></tr>
</table>
<div> <a name="ADDPFCST.PRNKEY"></a>
<h3>Parent key (PRNKEY)</h3>
<p>Specifies the parent key, which is the definition of the access path on a parent file of a referential constraint. Only unique constraints or the primary key constraint of a parent file can be used to define a referential constraint. The parent key is one or more fields that exist in the file specified on the PRNFILE parameter.
</p>
<p><b>Single values</b>
</p>
<dl>
<dt><b><u>*PRNFILE</u></b></dt>
<dd>The access path of the parent file is used when the access path is either a primary key constraint or a unique constraint.
</dd>
</dl>
<p><b>Other values (up to 120 repetitions)</b>
</p>
<dl>
<dt><b><i>name</i></b></dt>
<dd>Specify the name of the field for the constraint key you are defining. Each field name must exist in the file specified on the PRNFILE parameter. You can specify a maximum of 120 (but no duplicate) field names to define the parent key, where:
<ul>
<li>The fields can allow nulls.
</li>
<li>The field names are of the object type *NAME and are a maximum length of 10.
</li>
<li>The fields must be in ascending order.
</li>
<li>The fields must match the type and length attributes of the fields specified for the foreign key.
</li>
<li>The maximum number of bytes in a key is 32768 bytes (see the Database information in the iSeries Information Center at http://www.ibm.com/eserver/iseries/infocenter for more information on this limitation).
</li>
</ul>
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFCST.Top_Of_Page">Top</a></td></tr>
</table>
<div> <a name="ADDPFCST.DLTRULE"></a>
<h3>Delete rule (DLTRULE)</h3>
<p>Specifies the delete rule for a referential constraint between a parent file and dependent file. The <b>delete rule</b> restricts or defines the effect of deleting a record in both the parent file and the dependent file.
</p>
<dl>
<dt><b><u>*NOACTION</u></b></dt>
<dd>The no action delete rule is used. The delete rule is enforced at the end of the delete request. The following are attributes of the no action delete rule:
<ul>
<li>Deleting a record in parent file is permitted (not restricted) if data for a non-null parent key does not match data for a foreign key.
</li>
<li>Deleting a record in a parent file is restricted (does not occur) if data for a non-null parent key matches data for a foreign key.
</li>
</ul>
</dd>
<dt><b>*RESTRICT</b></dt>
<dd>The restrict delete rule is used. The delete rule is enforced at the beginning of the delete request. The following are attributes of the restrict delete rule:
<ul>
<li>Deleting a record in a parent file is permitted if data for a non-null parent key does not match data for a foreign key.
</li>
<li>Deleting a record in a parent file is restricted if data for a non-null parent key matches data for a foreign key.
</li>
</ul>
</dd>
<dt><b>*CASCADE</b></dt>
<dd>The cascade delete rule is used. Deleting a record in a parent file causes matching records in the dependent file to be deleted when data for a non-null parent key matches data for a foreign key.
</dd>
<dt><b>*SETNULL</b></dt>
<dd>The set null delete rule is used. Deleting a record in a parent file updates matching records in a dependent file if data for a non-null parent key matches data for a foreign key. If the matching foreign key field is null-capable, the value is set to null. If the matching foreign key field is not null-capable, the field is not updated.
<p>
<b>Note: </b>To use this rule, a minimum of one field in the foreign key access path must be null-capable.
</p>
</dd>
<dt><b>*SETDFT</b></dt>
<dd>The set default delete rule is used. The following are attributes of the set default delete rule:
<ul>
<li>Deleting a record in the parent file updates matching records in the dependent file when a data for a non-null parent key matches data for a foreign key. The matching foreign key values are set to the default value as defined by the default.
</li>
<li>The default foreign key value must match the corresponding parent key value when there are no null-capable fields.
</li>
</ul>
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFCST.Top_Of_Page">Top</a></td></tr>
</table>
<div> <a name="ADDPFCST.UPDRULE"></a>
<h3>Update rule (UPDRULE)</h3>
<p>Specifies the update rule for a referential constraint between a parent file and dependent file. The <b>update rule</b> restricts or defines the effect of updating a record in both the parent file and the dependent file.
</p>
<dl>
<dt><b><u>*NOACTION</u></b></dt>
<dd>The no action update rule is used. The update rule is enforced at the end of the update request. The following are attributes of the no action update rule:
<ul>
<li>Updating a record in parent file is permitted (not restricted) if data for a non-null parent key does not match data for a foreign key.
</li>
<li>Updating a record in a parent file is restricted (does not occur) if data for a non-null parent key matches data for a foreign key.
</li>
</ul>
</dd>
<dt><b>*RESTRICT</b></dt>
<dd>The restrict update rule is used. The update rule is enforced at the beginning of the update request. The following are attributes of the restrict update rule:
<ul>
<li>Updating a record in a parent file is permitted if data for a non-null parent key does not match data for a foreign key.
</li>
<li>Updating a record in a parent file is restricted if data for a non-null parent key matches data for a foreign key.
</li>
</ul>
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFCST.Top_Of_Page">Top</a></td></tr>
</table>
<div> <a name="ADDPFCST.CHKCST"></a>
<h3>Check constraint (CHKCST)</h3>
<p>Specifies the check constraint expression that is being added.
</p>
<dl>
<dt><b><i>character-value</i></b></dt>
<dd>Specify the check constraint expression. The expression has the same syntax as used for SQL check conditions. See the the SQL Reference information in the iSeries Information Center at http://www.ibm.com/eserver/iseries/infocenter for more information on syntax rules.
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFCST.Top_Of_Page">Top</a></td></tr>
</table>
<hr size="2" width="100%">
<div><h3><a name="ADDPFCST.COMMAND.EXAMPLES">Examples</a> </h3>
<p><b>Example 1: Adding a Unique Constraint</b>
</p>
<p>
<pre>
ADDPFCST FILE(MYLIB/LOCATIONS) TYPE(*UNQCST) KEY(REGION)
CST(Personnel_by_REGION)
</pre>
</p>
<p>This command adds a unique constraint to the LOCATIONS file in the MYLIB library. The field that defines the access path is REGION. The name of the access path is Personnel_by_REGION.
</p>
<p><b>Example 2: Adding a Referential Constraint</b>
</p>
<p>
<pre>
ADDPFCST FILE(ADMN/PERSONNEL) TYPE(*REFCST) KEY(REGION)
CST(1994Hires) PRNFILE(MYLIB/LOCATIONS)
PRNKEY(REGION) DLTRULE(*CASCADE)
UPDRULE(*RESTRICT)
</pre>
</p>
<p>This command adds a referential constraint to the PERSONNEL file in the ADMN library. The field that defines the access path is REGION, which is also the key for the parent file LOCATIONS in the MYLIB library. The name of the access path is 1994Hires. According to the delete rule of cascade, if a record in the LOCATIONS file is subsequently deleted, and that record matches a record in the PERSONNEL file, the record also will be deleted from the PERSONNEL file. According to the update rule of restrict, subsequent changes to the LOCATION file records defined in the constraint are restricted at the beginning of the update request.
</p>
<p><b>Example 3: Adding a Check Constraint</b>
</p>
<p>
<pre>
ADDPFCST FILE(PERSONNEL/SALARY) TYPE(*CHKCST)
CST(Upper_Salary_Limit) CHKCST('EMPSAL &lt;= 100000')
</pre>
</p>
<p>This command adds a check constraint to the SALARY file in the PERSONNEL library. The check constraint will ensure an employee's salary may be a maximum of 100,000.
</p>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFCST.Top_Of_Page">Top</a></td></tr>
</table>
<hr size="2" width="100%">
<div><h3><a name="ADDPFCST.ERROR.MESSAGES">Error messages</a> </h3>
<p><b><u>*ESCAPE Messages</u></b>
</p>
<dl>
<dt><b>CPF32B0</b></dt>
<dd>Constraint cannot be added to file &amp;1.
</dd>
<dt><b>CPF32B7</b></dt>
<dd>&amp;3 constraint(s) added to file &amp;1 but constraint(s) in error.
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFCST.Top_Of_Page">Top</a></td></tr>
</table>
</body>
</html>