98 lines
6.3 KiB
HTML
98 lines
6.3 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="reference" />
|
|
<meta name="DC.Title" content="Update tables with referential constraints" />
|
|
<meta name="abstract" content="If you are updating a parent table, you cannot modify a primary key for which dependent rows exist." />
|
|
<meta name="description" content="If you are updating a parent table, you cannot modify a primary key for which dependent rows exist." />
|
|
<meta name="DC.subject" content="UPDATE statement, and referential constraints, constraint, referential, updating tables, update rules for constraints, update rules" />
|
|
<meta name="keywords" content="UPDATE statement, and referential constraints, constraint, referential, updating tables, update rules for constraints, update rules" />
|
|
<meta name="DC.Relation" scheme="URI" content="rbafyupdate.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="rbafyupdaterules.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="rbafyjourg.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="rbafydicomm.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="rbafyrfupdating" />
|
|
<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>Update tables with referential constraints</title>
|
|
</head>
|
|
<body id="rbafyrfupdating"><a name="rbafyrfupdating"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Update tables with referential constraints</h1>
|
|
<div><p>If you are updating a <em>parent</em> table, you cannot modify a
|
|
primary key for which dependent rows exist. </p>
|
|
<div class="section"><p>Changing the key violates referential constraints for dependent
|
|
tables and leaves some rows without a parent. Furthermore, you cannot give
|
|
any part of a primary key a null value.</p>
|
|
</div>
|
|
<div class="section"><h4 class="sectiontitle">Update rules</h4><p>The action taken on dependent tables
|
|
when an UPDATE is performed on a parent table depends on the update rule specified
|
|
for the referential constraint. If no update rule was defined for a referential
|
|
constraint, the UPDATE NO ACTION rule is used. </p>
|
|
<dl><dt class="dlterm">UPDATE NO ACTION</dt>
|
|
<dd>Specifies that the row in the parent table can be updated if no other
|
|
row depends on it. If a dependent row exists in the relationship, the UPDATE
|
|
fails. The check for dependent rows is performed at the end of the statement.</dd>
|
|
<dt class="dlterm">UPDATE RESTRICT </dt>
|
|
<dd>Specifies that the row in the parent table can be updated if no other
|
|
row depends on it. If a dependent row exists in the relationship, the UPDATE
|
|
fails. The check for dependent rows is performed immediately.</dd>
|
|
</dl>
|
|
</div>
|
|
<div class="section"><p>The subtle difference between the RESTRICT rule and the NO ACTION
|
|
rule is easiest seen when looking at the interaction of triggers and referential
|
|
constraints. Triggers can be defined to fire either before or after an operation
|
|
(an UPDATE statement, in this case). A <em>before trigger</em> fires before
|
|
the UPDATE is performed and therefore before any checking of constraints.
|
|
An <em>after trigger</em> is fired after the UPDATE is performed, and after
|
|
a constraint rule of RESTRICT (where checking is performed immediately), but
|
|
before a constraint rule of NO ACTION (where checking is performed at the
|
|
end of the statement). The triggers and rules occur in the following order: </p>
|
|
</div>
|
|
<div class="section"> <ol><li>A <em>before trigger</em> is fired before the UPDATE and before a constraint
|
|
rule of RESTRICT or NO ACTION.</li>
|
|
<li>An <em>after trigger</em> is fired after a constraint rule of RESTRICT,
|
|
but before a NO ACTION rule.</li>
|
|
</ol>
|
|
</div>
|
|
<div class="section"><p>If you are updating a <em>dependent</em> table, any non-null foreign
|
|
key values that you change must match the primary key for each relationship
|
|
in which the table is a dependent. For example, department numbers in the
|
|
employee table depend on the department numbers in the department table. You
|
|
can assign an employee to no department (the null value), but not to a department
|
|
that does not exist.</p>
|
|
</div>
|
|
<div class="section"><p>If an UPDATE against a table with a referential constraint fails,
|
|
all changes made during the update operation are undone.</p>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<ul class="ullinks">
|
|
<li class="ulchildlink"><strong><a href="rbafyupdaterules.htm">Examples: UPDATE rules</a></strong><br />
|
|
These examples illustrate the UPDATE rules.</li>
|
|
</ul>
|
|
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafyupdate.htm" title="This topic shows the basic SQL statement and clauses that update data into tables and views. To change the data in a table, use the UPDATE statement.">Change data in a table using the UPDATE statement</a></div>
|
|
</div>
|
|
<div class="relref"><strong>Related reference</strong><br />
|
|
<div><a href="rbafyjourg.htm" title="The DB2 UDB for iSeries journal support supplies an audit trail and forward and backward recovery.">Journaling</a></div>
|
|
<div><a href="rbafydicomm.htm" title="The DB2 UDB for iSeries commitment control support provides a means to process a group of database changes like update, insert, DDL, or delete operations as a single unit of work (transaction).">Commitment control</a></div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |