ibm-information-center/dist/eclipse/plugins/i5OS.ic.sqlp_5.4.0.1/rbafyidentsequence.htm

77 lines
4.9 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="Comparison of identity columns and sequences" />
<meta name="abstract" content="While IDENTITY columns and sequences are similar in many ways, there are also differences." />
<meta name="description" content="While IDENTITY columns and sequences are similar in many ways, there are also differences." />
<meta name="DC.subject" content="sequences, compare with identity, identity column, compare with sequence" />
<meta name="keywords" content="sequences, compare with identity, identity column, compare with sequence" />
<meta name="DC.Relation" scheme="URI" content="rbafysequence.htm" />
<meta name="DC.Relation" scheme="URI" content="rbafysqlpidentity.htm" />
<meta name="DC.Relation" scheme="URI" content="rbafysequence.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="rbafyidentsequence" />
<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>Comparison of identity columns and sequences</title>
</head>
<body id="rbafyidentsequence"><a name="rbafyidentsequence"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Comparison of identity columns and sequences</h1>
<div><p>While IDENTITY columns and sequences are similar in many ways,
there are also differences. </p>
<div class="section"><p>Examine these differences before you decide which to use.</p>
</div>
<div class="section"><p>An identity column has the following characteristics: </p>
<ul><li>An identity column can be defined as part of a table only when the table
is created. Once a table is created, you cannot alter it to add an identity
column. (However, existing identity column characteristics may be altered.)</li>
<li>An identity column automatically generates values for a single table.</li>
<li>When an identity column is defined as GENERATED ALWAYS, the values used
are always generated by the database manager. Applications are not allowed
to provide their own values during the modification of the contents of the
table.</li>
<li>The IDENTITY_VAL_LOCAL function can be used to see the most recently assigned
value for an identity column.</li>
</ul>
<p>A sequence has the following characteristics:</p>
<ul><li> A sequence is a system object of type *DTAARA that is not tied to a table.</li>
<li>A sequence generates sequential values that can be used in any SQL statement.</li>
<li>There are two expressions used to retrieve the next values in the sequence
and to look at the previous value assigned for the sequence. The PREVIOUS
VALUE expression returns the most recently generated value for the specified
sequence for a previous statement within the current session. The NEXT VALUE
expression returns the next value for the specified sequence. The use of these
expressions allows the same value to be used across several SQL statements
within several tables.</li>
</ul>
<p>While these are not all of the characteristics of these two items,
these characteristics will assist you in determining which to use depending
on your database design and the applications using the database.</p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafysequence.htm" title="A sequence is an object that allows you to generate values quickly and easily.">Create and use sequences</a></div>
</div>
<div class="relref"><strong>Related reference</strong><br />
<div><a href="rbafysqlpidentity.htm" title="Every time that a new row is added to a table with an identity column, the identity column value in the new row is incremented (or decremented) by the system.">Create and alter an identity column</a></div>
<div><a href="rbafysequence.htm" title="A sequence is an object that allows you to generate values quickly and easily.">Create and use sequences</a></div>
</div>
</div>
</body>
</html>