ibm-information-center/dist/eclipse/plugins/i5OS.ic.cli_5.4.0.1/rzadpfnpkey.htm

228 lines
15 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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="SQLPrimaryKeys - Get primary key columns of a table" />
<meta name="DC.Relation" scheme="URI" content="rzadphdapi.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1999, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1999, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rzadpfnpkey" />
<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>SQLPrimaryKeys</title>
</head>
<body id="rzadpfnpkey"><a name="rzadpfnpkey"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">SQLPrimaryKeys - Get primary key columns of a table</h1>
<div><div class="section"><h4 class="sectiontitle">Purpose</h4> <p><samp class="codeph">SQLPrimaryKeys()</samp> returns
a list of column names that comprise the primary key for a table. The information
is returned in an SQL result set, which can be retrieved using the same functions
that are used to process a result set that is generated by a query.</p>
</div>
<div class="section"><h4 class="sectiontitle">Syntax</h4><pre>SQLRETURN SQLPrimaryKeys (SQLHSTMT StatementHandle,
SQLCHAR *CatalogName,
SQLSMALLINT NameLength1,
SQLCHAR *SchemaName,
SQLSMALLINT NameLength2,
SQLCHAR *TableName,
SQLSMALLINT NameLength3);</pre>
</div>
<div class="section"><h4 class="sectiontitle">Function arguments</h4>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" width="100%" frame="hsides" border="1" rules="all"><caption>Table 1. SQLPrimaryKeys arguments</caption><thead align="left"><tr><th align="left" valign="bottom" width="20.793950850661624%" id="d0e47">Data type</th>
<th align="left" valign="bottom" width="25.330812854442343%" id="d0e49">Argument </th>
<th align="left" valign="bottom" width="10.58601134215501%" id="d0e51">Use </th>
<th align="left" valign="bottom" width="43.28922495274102%" id="d0e53">Description </th>
</tr>
</thead>
<tbody><tr><td align="left" valign="top" width="20.793950850661624%" headers="d0e47 ">SQLCHAR *</td>
<td align="left" valign="top" width="25.330812854442343%" headers="d0e49 "><em>CatalogName</em> </td>
<td align="left" valign="top" width="10.58601134215501%" headers="d0e51 ">Input </td>
<td align="left" valign="top" width="43.28922495274102%" headers="d0e53 ">Catalog qualifier of a 3 part table name.
<p> This must be a NULL pointer or a zero length string.</p>
</td>
</tr>
<tr><td align="left" valign="top" width="20.793950850661624%" headers="d0e47 ">SQLCHAR *</td>
<td align="left" valign="top" width="25.330812854442343%" headers="d0e49 "><em>SchemaName</em></td>
<td align="left" valign="top" width="10.58601134215501%" headers="d0e51 ">Input </td>
<td align="left" valign="top" width="43.28922495274102%" headers="d0e53 ">Schema qualifier of table name.</td>
</tr>
<tr><td align="left" valign="top" width="20.793950850661624%" headers="d0e47 ">SQLCHAR *</td>
<td align="left" valign="top" width="25.330812854442343%" headers="d0e49 "><em>TableName</em> </td>
<td align="left" valign="top" width="10.58601134215501%" headers="d0e51 ">Input </td>
<td align="left" valign="top" width="43.28922495274102%" headers="d0e53 ">Table name.</td>
</tr>
<tr><td align="left" valign="top" width="20.793950850661624%" headers="d0e47 ">SQLHSTMT </td>
<td align="left" valign="top" width="25.330812854442343%" headers="d0e49 "><em>StatementHandle </em></td>
<td align="left" valign="top" width="10.58601134215501%" headers="d0e51 ">Input </td>
<td align="left" valign="top" width="43.28922495274102%" headers="d0e53 ">Statement handle.</td>
</tr>
<tr><td align="left" valign="top" width="20.793950850661624%" headers="d0e47 ">SQLSMALLINT </td>
<td align="left" valign="top" width="25.330812854442343%" headers="d0e49 "><em>NameLength2</em> </td>
<td align="left" valign="top" width="10.58601134215501%" headers="d0e51 ">Input</td>
<td align="left" valign="top" width="43.28922495274102%" headers="d0e53 ">Length of <span class="synph"><span class="var">SchemaName</span>.</span></td>
</tr>
<tr><td align="left" valign="top" width="20.793950850661624%" headers="d0e47 ">SQLSMALLINT </td>
<td align="left" valign="top" width="25.330812854442343%" headers="d0e49 "><em>NameLength3</em> </td>
<td align="left" valign="top" width="10.58601134215501%" headers="d0e51 ">Input </td>
<td align="left" valign="top" width="43.28922495274102%" headers="d0e53 ">Length of <span class="synph"><span class="var">TableName</span>.</span></td>
</tr>
<tr><td align="left" valign="top" width="20.793950850661624%" headers="d0e47 ">SQLSMALLINT</td>
<td align="left" valign="top" width="25.330812854442343%" headers="d0e49 "><em>NameLength1</em> </td>
<td align="left" valign="top" width="10.58601134215501%" headers="d0e51 ">Input </td>
<td align="left" valign="top" width="43.28922495274102%" headers="d0e53 ">Length of <span class="synph"><span class="var">CatalogName</span>.</span></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section"><h4 class="sectiontitle">Usage</h4><p><samp class="codeph">SQLPrimaryKeys()</samp> returns
the primary key columns from a single table. Search patterns
cannot be used to specify the schema qualifier or the table name.</p>
<p>The
result set contains the columns that are listed in <a href="#rzadpfnpkey__tbprkey">Table 2</a>,
ordered by TABLE_CAT, TABLE_SCHEM, TABLE_NAME, and ORDINAL_POSITION.</p>
<p>Because
calls to <samp class="codeph">SQLPrimaryKeys()</samp> in many cases map to a complex
and, thus, expensive query against the system catalog, they should be used
sparingly, and the results saved rather than repeating calls.</p>
<p>Although
new columns might be added and the names of the existing columns might be
changed in future releases, the position of the current columns does not change.</p>
<div class="tablenoborder"><a name="rzadpfnpkey__tbprkey"><!-- --></a><table cellpadding="4" cellspacing="0" summary="" id="rzadpfnpkey__tbprkey" width="100%" frame="hsides" border="1" rules="rows"><caption>Table 2. Columns returned by SQLPrimaryKeys</caption><thead align="left"><tr><th align="left" valign="bottom" width="23.00556586270872%" id="d0e174">Column number/name</th>
<th align="left" valign="bottom" width="20.037105751391465%" id="d0e176">Data type</th>
<th align="left" valign="bottom" width="56.95732838589982%" id="d0e178">Description</th>
</tr>
</thead>
<tbody><tr><td align="left" valign="top" width="23.00556586270872%" headers="d0e174 ">1  TABLE_CAT</td>
<td align="left" valign="top" width="20.037105751391465%" headers="d0e176 ">VARCHAR (128)</td>
<td align="left" valign="top" width="56.95732838589982%" headers="d0e178 ">The current server.</td>
</tr>
<tr><td align="left" valign="top" width="23.00556586270872%" headers="d0e174 ">2  TABLE_SCHEM</td>
<td align="left" valign="top" width="20.037105751391465%" headers="d0e176 ">VARCHAR (128)</td>
<td align="left" valign="top" width="56.95732838589982%" headers="d0e178 ">The name of the schema containing TABLE_NAME.</td>
</tr>
<tr><td align="left" valign="top" width="23.00556586270872%" headers="d0e174 ">3  TABLE_NAME </td>
<td align="left" valign="top" width="20.037105751391465%" headers="d0e176 ">VARCHAR (128) not NULL</td>
<td align="left" valign="top" width="56.95732838589982%" headers="d0e178 ">Name of the specified table.</td>
</tr>
<tr><td align="left" valign="top" width="23.00556586270872%" headers="d0e174 ">4  COLUMN_NAME</td>
<td align="left" valign="top" width="20.037105751391465%" headers="d0e176 ">VARCHAR (128) not NULL</td>
<td align="left" valign="top" width="56.95732838589982%" headers="d0e178 ">Primary Key column name.</td>
</tr>
<tr><td align="left" valign="top" width="23.00556586270872%" headers="d0e174 ">5  ORDINAL_POSITION </td>
<td align="left" valign="top" width="20.037105751391465%" headers="d0e176 ">SMALLINT not NULL</td>
<td align="left" valign="top" width="56.95732838589982%" headers="d0e178 ">Column sequence number in the primary key,
starting with 1.</td>
</tr>
<tr><td align="left" valign="top" width="23.00556586270872%" headers="d0e174 ">6  PK_NAME </td>
<td align="left" valign="top" width="20.037105751391465%" headers="d0e176 ">VARCHAR(128)</td>
<td align="left" valign="top" width="56.95732838589982%" headers="d0e178 ">Primary key identifier. NULL if not applicable
to the data source.</td>
</tr>
<tr><td colspan="3" align="left" valign="top" headers="d0e174 d0e176 d0e178 "> <div class="note"><span class="notetitle">Note:</span> The column
names used by DB2<sup>®</sup> UDB
CLI follow the X/Open CLI CAE specification style. The column types, contents
and order are identical to those defined for the <samp class="codeph">SQLPrimaryKeys()</samp> result
set in ODBC.</div>
</td>
</tr>
</tbody>
</table>
</div>
<p>If the specified table does not contain a primary key, an empty
result set is returned. </p>
</div>
<div class="section"><h4 class="sectiontitle">Return codes</h4><div class="p"> <ul><li>SQL_SUCCESS</li>
<li>SQL_SUCCESS_WITH_INFO</li>
<li>SQL_STILL_EXECUTING</li>
<li>SQL_ERROR</li>
<li>SQL_INVALID_HANDLE</li>
</ul>
</div>
</div>
<div class="section"><h4 class="sectiontitle">Error conditions</h4>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" width="100%" frame="hsides" border="1" rules="rows"><caption>Table 3. SQLPrimaryKeys SQLSTATEs</caption><thead align="left"><tr><th align="left" valign="bottom" width="12.962962962962962%" id="d0e267">SQLSTATE </th>
<th align="left" valign="bottom" width="29.074074074074076%" id="d0e269">Description </th>
<th align="left" valign="bottom" width="57.96296296296296%" id="d0e271">Explanation </th>
</tr>
</thead>
<tbody><tr><td align="left" valign="top" width="12.962962962962962%" headers="d0e267 "><strong>24</strong>000 </td>
<td align="left" valign="top" width="29.074074074074076%" headers="d0e269 ">Cursor state that is not valid</td>
<td align="left" valign="top" width="57.96296296296296%" headers="d0e271 ">A cursor is already opened on the statement
handle.</td>
</tr>
<tr><td align="left" valign="top" width="12.962962962962962%" headers="d0e267 "><strong>40</strong>003 <strong>08</strong>S01</td>
<td align="left" valign="top" width="29.074074074074076%" headers="d0e269 ">Communication link failure</td>
<td align="left" valign="top" width="57.96296296296296%" headers="d0e271 ">The communication link between the application
and data source fails before the function is completed.</td>
</tr>
<tr><td align="left" valign="top" width="12.962962962962962%" headers="d0e267 "><strong>HY</strong>001 </td>
<td align="left" valign="top" width="29.074074074074076%" headers="d0e269 ">Memory allocation failure</td>
<td align="left" valign="top" width="57.96296296296296%" headers="d0e271 ">DB2 UDB CLI is unable to allocate memory
required to support the processing or completion of the function.</td>
</tr>
<tr><td align="left" valign="top" width="12.962962962962962%" headers="d0e267 "><strong>HY</strong>008</td>
<td align="left" valign="top" width="29.074074074074076%" headers="d0e269 ">Operation canceled</td>
<td align="left" valign="top" width="57.96296296296296%" headers="d0e271 ">&nbsp;</td>
</tr>
<tr><td align="left" valign="top" width="12.962962962962962%" headers="d0e267 "><strong>HY</strong>010 </td>
<td align="left" valign="top" width="29.074074074074076%" headers="d0e269 ">Function sequence error</td>
<td align="left" valign="top" width="57.96296296296296%" headers="d0e271 ">The function is called while in a data-at-processing
(<samp class="codeph">SQLParamData()</samp>, <samp class="codeph">SQLPutData()</samp>) operation.</td>
</tr>
<tr><td align="left" valign="top" width="12.962962962962962%" headers="d0e267 "><strong>HY</strong>014 </td>
<td align="left" valign="top" width="29.074074074074076%" headers="d0e269 ">No more handles</td>
<td align="left" valign="top" width="57.96296296296296%" headers="d0e271 ">DB2 UDB CLI is unable to allocate a handle
due to internal resources.</td>
</tr>
<tr><td valign="top" width="12.962962962962962%" headers="d0e267 "><strong>HY</strong>021</td>
<td valign="top" width="29.074074074074076%" headers="d0e269 ">Internal descriptor that is not valid </td>
<td valign="top" width="57.96296296296296%" headers="d0e271 ">The internal descriptor cannot be addressed or allocated,
or it contains a value that is not valid .</td>
</tr>
<tr><td align="left" valign="top" width="12.962962962962962%" headers="d0e267 "><strong>HY</strong>090 </td>
<td align="left" valign="top" width="29.074074074074076%" headers="d0e269 ">String or buffer length that is not valid</td>
<td align="left" valign="top" width="57.96296296296296%" headers="d0e271 ">The value of one of the name length arguments
is less than 0, but not equal to SQL_NTS.</td>
</tr>
<tr><td align="left" valign="top" width="12.962962962962962%" headers="d0e267 "><strong>HY</strong>C00 </td>
<td align="left" valign="top" width="29.074074074074076%" headers="d0e269 ">Driver not capable</td>
<td align="left" valign="top" width="57.96296296296296%" headers="d0e271 ">DB2 UDB CLI does not support <span class="synph"><span class="var">catalog</span></span> as
a qualifier for table name.</td>
</tr>
<tr><td align="left" valign="top" width="12.962962962962962%" headers="d0e267 "><strong>HY</strong>T00</td>
<td align="left" valign="top" width="29.074074074074076%" headers="d0e269 ">Timeout expired</td>
<td align="left" valign="top" width="57.96296296296296%" headers="d0e271 ">&nbsp;</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section"><h4 class="sectiontitle">Restrictions</h4><p>None.</p>
</div>
<div class="section"><h4 class="sectiontitle">References</h4><div class="p"> <ul><li><a href="rzadpfnfkey.htm#rzadpfnfkey">SQLForeignKeys - Get the list of foreign key columns</a></li>
<li><a href="rzadpfnstats.htm#rzadpfnstats">SQLStatistics - Get index and statistics information for a base table</a></li>
</ul>
</div>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzadphdapi.htm" title="This topic provides a description of each CLI function.">DB2 UDB CLI functions</a></div>
</div>
</div>
</body>
</html>