DB_PrimaryKeys Function

Action

Returns the column names that make up the primary key for a table. Information is returned as a result set on the statement handle. This function does not support returning primary keys from multiple tables in a single call.

Syntax

hstmnt = DB_PrimaryKeys (hdbc, catalog-name, schema-name, table-name)
Variable Description
hstmnt

The returned handle to the executed SQL statement. This is an input parameter for other DBTester functions, for example DB_FetchNext. HSQL.

hdbc

The handle to a database as returned by DB_Connect. HDATABASE.

catalog-name

Catalog name. STRING.

schema-name

String search pattern for schema names. STRING.

table-name

String search pattern for table names. STRING.

Notes

  • DB_PrimaryKeys corresponds to SQLPrimaryKeys. For additional information about SQLPrimaryKeys, see SQLPrimaryKeys Function.

  • The table-name argument is required and cannot contain a wildcard.

  • The following wildcard characters are supported for arguments:
    Wildcard character Matches
    % The percent sign matches any character sequence.
    _ The underscore matches any single character.
  • To omit a variable argument, which is not a required argument, specify the argument as an empty string ("").

  • When you receive a valid statement handle, you can call DB_FetchNext or DB_FetchPrevious to manipulate the information.

Example

[ ] STRING cat, sch, table, ignore, table-name, pkcol, kname 
[ ] hstmnt = DB_PrimaryKeys (hdbc, cat, sch,table)
[ ] // retrieve primary key column and key sequence; ignore the rest.
[-] while (DB_FetchNext (hstmt, ignore, ignore, table-name, pkcol, ignore, kname) == TRUE) { 
	[ ] //print table name, its PK columns, and key sequence ...
[-] }