Retrieving primary keys of a table
The JDBC Metadata Explorer enables the retrieval of primary keys (name and column information) of a specified database table.
Input
Add the element <primarykeys resulttag="ResultElementName"/> to an input XML document with any root element, and specify a valid XML name within the attribute resulttag. It is required to specify a table in element <table>; the elements <catalog> and <schema> are optional here.
<Root>
<primarykeys resulttag="ResultElementName">
<catalog>Catalog</catalog>
<schema>Database schema</schema>
<table>Database table (mandatory, may not be empty)</table>
</primarykeys>
</Root>
Output
The output XML structure contains a root element <Data> with a child element whose name has been specified in the input structure within the attribute resulttag. It contains metadata to each primary key of the table. If there are multiple result sets (i. e. more than one primary key column), each will be output in a separate element.
<Data>
<ResultElementName>
<PrimayKeyProperty> value </PrimayKeyProperty>
...
</ResultElementName>
</Data>
Further information on each column property can be found here.
Example
An input XML document contains the following XML structure to output the primary keys of table HISTORY:
<Root>
<primarykeys resulttag="historykeys">
<schema></schema>
<table>HISTORY</table>
</primarykeys>
</Root>
Then, the JDBC Metadata Explorer outputs e. g. the following result XML document:
<Data>
<historykeys>
<TABLE_CAT />
<TABLE_SCHEM>APP</TABLE_SCHEM>
<TABLE_NAME>HISTORY</TABLE_NAME>
<COLUMN_NAME>PID</COLUMN_NAME>
<KEY_SEQ>1</KEY_SEQ>
<PK_NAME>SQL090505161403130</PK_NAME>
</historykeys>
</Data>