105 lines
6.7 KiB
HTML
105 lines
6.7 KiB
HTML
|
<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<!DOCTYPE html
|
||
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
<html lang="en-us" xml:lang="en-us">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
|
<meta name="security" content="public" />
|
||
|
<meta name="Robots" content="index,follow" />
|
||
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
||
|
<meta name="DC.Type" content="concept" />
|
||
|
<meta name="DC.Title" content="Define the parent file in a referential constraint" />
|
||
|
<meta name="abstract" content="A parent file must be a physical file with a maximum of one member. You can create a new file or use an existing file when you define the parent file." />
|
||
|
<meta name="description" content="A parent file must be a physical file with a maximum of one member. You can create a new file or use an existing file when you define the parent file." />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbaforzahfrce.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../cl/crtpf.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../cl/addpfcst.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../cl/rmvpfcst.htm" />
|
||
|
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
|
||
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
|
||
|
<meta name="DC.Format" content="XHTML" />
|
||
|
<meta name="DC.Identifier" content="rbaforzahfrci" />
|
||
|
<meta name="DC.Language" content="en-us" />
|
||
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
||
|
<!-- US Government Users Restricted Rights -->
|
||
|
<!-- Use, duplication or disclosure restricted by -->
|
||
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
||
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
||
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
||
|
<title>Define the parent file in a referential constraint</title>
|
||
|
</head>
|
||
|
<body id="rbaforzahfrci"><a name="rbaforzahfrci"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Define the parent file in a referential constraint</h1>
|
||
|
<div><p>A parent file must be a physical file with a maximum of one member.
|
||
|
You can create a new file or use an existing file when you define the parent
|
||
|
file.</p>
|
||
|
<p>The concept of a parent key applies only in terms of a referential constraint.
|
||
|
When a referential constraint is added to the dependent file, a parent key
|
||
|
is required for the parent file. To prepare for this, you must first add either
|
||
|
a primary key constraint or a unique constraint to the parent file with the
|
||
|
appropriate set of fields for the key. When the referential constraint is
|
||
|
added, a search is conducted of unique constraints (and primary key) for a
|
||
|
match. If a match is found, then the access path of the constraint is used
|
||
|
as the parent key in the referential constraint relationship.</p>
|
||
|
<div class="p">To create a new physical file as a parent file, follow these steps:<ol><li>Use the Create Physical File (CRTPF) command to create the file.</li>
|
||
|
<li>Use the Add Physical File Constraint (ADDPFCST) command to either add
|
||
|
a primary key constraint or a unique constraint. The primary key can be null-capable,
|
||
|
but the system creates an implicit check constraint to prevent the insertion
|
||
|
of null values in the field.</li>
|
||
|
</ol>
|
||
|
<div class="note"><span class="notetitle">Note:</span> You can use the SQL CREATE TABLE statement to perform the preceding
|
||
|
steps with one step.</div>
|
||
|
</div>
|
||
|
<p>To use an existing file as a parent file, choose from the following options:</p>
|
||
|
<ul><li class="liexpand">You can add a primary key constraint to a file with the ADDPFCST command.
|
||
|
Specify *PRIKEY for the TYPE parameter. You must also specify the key field
|
||
|
or fields with the KEY parameter. <p>If a primary key constraint already exists
|
||
|
for the file, the ADDPFCST command with TYPE(*PRIKEY) will fail because a
|
||
|
file can have only one primary key. If you want a different primary key constraint,
|
||
|
you must first remove the existing primary key constraint with the Remove
|
||
|
Physical File Constraint (RMVPFCST) command. Then you can add a new primary
|
||
|
key constraint.</p>
|
||
|
</li>
|
||
|
<li class="liexpand">You can add a unique constraint to a file with the ADDPFCST command. Specify
|
||
|
*UNQCST for the TYPE parameter. You must also specify the key field or fields
|
||
|
with the KEY parameter. You can also add a unique constraint with the Structured
|
||
|
Query Language (SQL) ALTER TABLE statement. <p>If the parent file does not
|
||
|
have a primary key or unique constraint that can be used as the parent key,
|
||
|
the system will attempt to automatically add a primary key constraint when
|
||
|
adding a referential constraint.</p>
|
||
|
<p>If the parent file has a uniquely keyed
|
||
|
access path, where the access path fields match the foreign key's fields (both
|
||
|
for the number of fields and matching attributes), then a primary key constraint
|
||
|
will be implicitly added to the parent file. This will become the parent key
|
||
|
for the referential constraint.</p>
|
||
|
<p>If the parent file is arrival sequence
|
||
|
access path, then if the fields specified for the parent key match the foreign
|
||
|
key's fields (matching attributes), then a primary key constraint will be
|
||
|
implicitly added to the parent file. This will become the parent key for the
|
||
|
referential constraint.</p>
|
||
|
</li>
|
||
|
</ul>
|
||
|
<div class="section" id="rbaforzahfrci__rbaforzahfrc9"><a name="rbaforzahfrci__rbaforzahfrc9"><!-- --></a><h4 class="sectiontitle">What to do when you cannot define a parent
|
||
|
key</h4><p>For an existing file with a primary key or unique constraint,
|
||
|
if neither constraint will suffice as the parent key, there are options you
|
||
|
can turn to.</p>
|
||
|
<div class="p">You can take either of the following actions
|
||
|
when you cannot define a parent key.<ul><li>Delete the file and create it again with the appropriate keys.</li>
|
||
|
<li>Add a unique or primary key constraint to the created file.</li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div>
|
||
|
<div class="familylinks">
|
||
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbaforzahfrce.htm" title="You can add referential constraints on physical files with no more than one member. A referential constraint is a file-level attribute; therefore, you can create the constraint before the member exists.">Add referential constraints</a></div>
|
||
|
</div>
|
||
|
<div class="relref"><strong>Related reference</strong><br />
|
||
|
<div><a href="../cl/crtpf.htm">Create Physical File (CRTPF) command</a></div>
|
||
|
<div><a href="../cl/addpfcst.htm">Add Physical File Constraint (ADDPFCST) command</a></div>
|
||
|
<div><a href="../cl/rmvpfcst.htm">Remove Physical File Constraint (RMVPFCST) command</a></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|