ibm-information-center/dist/eclipse/plugins/i5OS.ic.db2_5.4.0.1/rbafzmstsequences.htm

75 lines
4.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 xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="dc.language" scheme="rfc1766" 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. -->
<meta name="dc.date" scheme="iso8601" content="2005-09-19" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<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="keywords" content="sequences" />
<title>Sequences</title>
<link rel="stylesheet" type="text/css" href="ibmidwb.css" />
<link rel="stylesheet" type="text/css" href="ic.css" />
</head>
<body>
<a id="Top_Of_Page" name="Top_Of_Page"></a><!-- Java sync-link -->
<script language = "Javascript" src = "../rzahg/synch.js" type="text/javascript"></script>
<a name="sequences"></a>
<h2 id="sequences"><a href="rbafzmst02.htm#ToC_42">Sequences</a></h2><a id="idx111" name="idx111"></a>
<p>A sequence is a stored object that simply generates a sequence of numbers
in a monotonically ascending (or descending) order. Sequences provide a way
to have the database manager automatically generate unique integer and decimal
primary keys, and to coordinate keys across multiple rows and tables. A sequence
can be used to exploit parallelization, instead of programmatically generating
unique numbers by locking the most recently used value and then incrementing
it.</p>
<p>Sequences are ideally suited to the task of generating unique key values.
One sequence can be used for many tables, or a separate sequence can be created
for each table requiring generated keys. A sequence has the following properties:</p>
<ul>
<li>Can have guaranteed, unique values, assuming that the sequence is not
reset and does not allow the values to cycle.</li>
<li>Can have increasing or decreasing values within a defined range.</li>
<li>Can have an increment value other than 1 between consecutive values (the
default is 1).</li>
<li>Is recoverable.</li></ul>
<p>Values for a given sequence are automatically generated by the database
manager. Use of a sequence in the database avoids the performance bottleneck
that results when an application implements sequences outside the database.
The counter for the sequence is incremented (or decremented) independently
from the transaction.</p>
<p>In some cases, gaps can be introduced in a sequence. A gap can occur when
a given transaction increments a sequence two times. The transaction may see
a gap in the two numbers that are generated because there may be other transactions
concurrently incrementing the same sequence. A user may not realize that other
users are drawing from the same sequence. Furthermore, it is possible that
a given sequence can appear to have generated gaps in the numbers, because
a transaction that may have generated a sequence number may have rolled back.
Updating a sequence is not part of a transaction's unit of recovery.</p>
<p>A sequence is created with a CREATE SEQUENCE statement. A sequence can
be referenced using a <span class="italic">sequence-reference</span>. A sequence
reference can appear most places that an expression can appear. A sequence
reference can specify whether the value to be returned is a newly generated
value, or the previously generated value. For more information, see <a href="rbafzmstcsequence.htm#csequence">CREATE SEQUENCE</a> and <a href="rbafzmstdatetimearith.htm#seqref">Sequence reference</a>.</p>
<p>Although there are similarities, a sequence is different than an identity
column. A sequence is an object, whereas an identity column is a part of a
table. A sequence can be used with multiple tables, but an identity column
is part of a single table.</p>
<hr /><br />
[ <a href="#Top_Of_Page">Top of Page</a> | <a href="rbafzmstch1routines.htm">Previous Page</a> | <a href="rbafzmstauthown.htm">Next Page</a> | <a href="rbafzmst02.htm#wq1">Contents</a> |
<a href="rbafzmstindex.htm#index">Index</a> ]
<a id="Bot_Of_Page" name="Bot_Of_Page"></a>
</body>
</html>