On this page

SHOW FK

Core command SHOW FOREIGN KEYS SH FK SHFK

Shows the foreign keys declared by a table and what they reference.

Syntax

SHOW FK [<schema>.]<table>

Arguments

ArgumentRequiredValuesDefault
<table>YesThe exact table name, in any caseNone
<schema>.NoThe schema of the table, followed by a dotThe current schema

Examples

SHOW FK ORDERS;
SHOW FOREIGN KEYS SALES.ORDERS;

Example session

WORLD> SHOW FK REGION;
|-------------|-|-------------|----------------|-----------------|
|FK_NAME      |#|COLUMN       |REFERENCES_TABLE|REFERENCES_COLUMN|
|-------------|-|-------------|----------------|-----------------|
|CONSTRAINT_8F|1|COUNTRY_CODE2|COUNTRY         |CODE2            |
|-------------|-|-------------|----------------|-----------------|
Illustrative output: the values come from the WORLD sample and the practice connections of the how-to on QA and production copies of WORLD, and the layout from this release; it was not captured from a BroadSQL run, and your timings will differ.

Details

Output

One row per column of each foreign key: the constraint name, the column position within the key (#), the column of this table, and the table and column it references. The rows of a composite foreign key follow each other in key order. A referenced table in another schema is shown qualified.

SHOW REFERENCES gives the opposite direction: the foreign keys of other tables that point to this one.

Table name and errors

The table is found as for DESCR: in the given schema or the current one, tried as typed, then in upper case, then in lower case, and matched exactly. A table that declares no foreign key is reported as such. The command fails when no table name is given, when the table does not exist or is ambiguous, or when the JDBC driver cannot provide foreign key metadata.

Used in these how-tos

Last modified in release 5.5.0.

Found something wrong or unclear on this page? , with the page address.