98 lines
6.6 KiB
HTML
98 lines
6.6 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="Prevent duplicate key values" />
|
||
|
<meta name="abstract" content="DB2 Universal Database for iSeries allows records with duplicate key values in your files. However, you might want to prevent duplicate key values in some of your files." />
|
||
|
<meta name="description" content="DB2 Universal Database for iSeries allows records with duplicate key values in your files. However, you might want to prevent duplicate key values in some of your files." />
|
||
|
<meta name="DC.subject" content="preventing, duplicate key value, key field, preventing duplicate, field, preventing duplicate key, duplicate key field" />
|
||
|
<meta name="keywords" content="preventing, duplicate key value, key field, preventing duplicate, field, preventing duplicate key, duplicate key field" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafoksapa.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbaforzahfcoa.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../dds/kickoff.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="rbafoprvdupk" />
|
||
|
<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>Prevent duplicate key values</title>
|
||
|
</head>
|
||
|
<body id="rbafoprvdupk"><a name="rbafoprvdupk"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Prevent duplicate key values</h1>
|
||
|
<div><p>DB2
|
||
|
Universal Database™ for iSeries™ allows records with duplicate key values
|
||
|
in your files. However, you might want to prevent duplicate key values in
|
||
|
some of your files.</p>
|
||
|
<p>For example, you can create a file where the key field is defined as the
|
||
|
customer number field. In this case, you want the system to ensure that each
|
||
|
record in the file has a unique customer number.</p>
|
||
|
<p>You
|
||
|
can prevent duplicate key values in your files by specifying the UNIQUE keyword
|
||
|
in data description specifications (DDS). With the UNIQUE keyword specified,
|
||
|
a record cannot be entered or copied into a file if its key value is the same
|
||
|
as the key value of a record already existing in the file. You can also use
|
||
|
unique constraints to enforce the integrity of unique keys.</p>
|
||
|
<p>If records with duplicate key values already exist in a physical file,
|
||
|
the associated logical file cannot have the UNIQUE keyword specified. If you
|
||
|
try to create a logical file with the UNIQUE keyword specified, and the associated
|
||
|
physical file contains duplicate key values, the logical file is not created.
|
||
|
The system sends you a message stating this and sends you messages (as many
|
||
|
as 20) indicating which records contain duplicate key values.</p>
|
||
|
<p>When the UNIQUE keyword is specified for a file, any record added to the
|
||
|
file cannot have a key value that duplicates the key value of an existing
|
||
|
record in the file, regardless of the file used to add the new record. For
|
||
|
example, two logical files LF1 and LF2 are based on the physical file PF1.
|
||
|
The UNIQUE keyword is specified for LF1. If you use LF2 to add a record to
|
||
|
PF1, you cannot add the record if it causes a duplicate key value in LF1.</p>
|
||
|
<p>If any of the key fields allow null values, null values that are inserted
|
||
|
into those fields might or might not cause duplicates depending on how the
|
||
|
access path was defined when the file was created. The *INCNULL parameter
|
||
|
of the UNIQUE keyword indicates that null values are included when determining
|
||
|
whether duplicates exist in the unique access path. The *EXCNULL parameter
|
||
|
indicates that null values are not included when determining whether duplicate
|
||
|
values exist. </p>
|
||
|
<p>The following example shows the DDS for a logical file that requires unique
|
||
|
key values:</p>
|
||
|
<pre>|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
|
||
|
A* ORDER TRANSACTION LOGICAL FILE (ORDFILL)
|
||
|
A UNIQUE
|
||
|
A R ORDHDR PFILE(ORDHDRP)
|
||
|
A K ORDER
|
||
|
A
|
||
|
A R ORDDTL PFILE(ORDDTLP)
|
||
|
A K ORDER
|
||
|
A K LINE
|
||
|
A</pre>
|
||
|
<p>In this example, the contents of the key fields (the <em>Order</em> field
|
||
|
for the ORDHDR record format, and the <em>Order</em> and <em>Line</em> fields
|
||
|
for the ORDDTL record format) must be unique whether the record is added through
|
||
|
the ORDHDRP file, the ORDDTLP file, or the logical file defined here. With
|
||
|
the <em>Line</em> field specified as a second key field in the ORDDTL record
|
||
|
format, the same value can exist in the <em>Order</em> key field in both physical
|
||
|
files. Because the physical file ORDDTLP has two key fields and the physical
|
||
|
file ORDHDRP has only one, the key values in the two files do not conflict.</p>
|
||
|
</div>
|
||
|
<div>
|
||
|
<div class="familylinks">
|
||
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafoksapa.htm" title="A keyed sequence access path for database files is based on the contents of the key fields as defined in data description specifications (DDS). This topic describes how the key fields are arranged for the file.">Use a keyed sequence access path for database files</a></div>
|
||
|
</div>
|
||
|
<div class="relconcepts"><strong>Related concepts</strong><br />
|
||
|
<div><a href="rbaforzahfcoa.htm" title="A constraint is a restriction or limitation placed on a file to ensure that the data in your database remains consistent as you add, change, and remove records. These topics describe how to use constraints to ensure data consistency.">Control the integrity of your database with constraints</a></div>
|
||
|
<div><a href="../dds/kickoff.htm">DDS concepts</a></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|