DB_ForeignKeys Function

Action

Returns either a list of foreign keys, which are columns in the specified table that refer to primary keys in other tables, or a list of foreign keys in other tables that refer to the primary key in the specified table. The list is returned as a result set on the statement handle.

Syntax

hstmnt = DB_ForeignKeys (hdbc, pcatalog-name, pschema-name, ptable-name, fcatalog-name, fschema-name, ftable-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.

pcatalog-name

Primary key table catalog name. STRING.

pschema-name

Primary key table schema name. STRING.

ptable-name

Primary key table name. STRING.

fcatalog-name

Foreign key catalog name. STRING.

fschema-name

Foreign key schema name. STRING.

ftable-name

Foreign key table name. STRING.

Notes

  • DB_ForeignKeys corresponds to SQLForeignKeys. For additional information about SQLForeignKeys, see SQLForeignKeys Function.

  • The arguments ptable-name and ftable-name cannot contain wildcards.
  • 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 pcat, psch, ptable, fcat, fsch, ftable, ignore, fkcol, key-seq 
[ ] hstmnt = DB_ForeignKeys (hdbc, pcat, psch, ptable, fcat, fsch, ftable)
[ ] // retrieve foreign key column and key sequence; ignore the rest.
[-] while (DB_FetchNext (hstmt, ignore, ignore, ignore, ignore, ignore, ignore, ignore, fkcol, key-seq) == TRUE) { 
	[ ] //print FK columns and key sequence ...
[-] }