On this page
SHOW FK
Shows the foreign keys declared by a table and what they reference.
Syntax
SHOW FK [<schema>.]<table>
Arguments
| Argument | Required | Values | Default |
|---|---|---|---|
<table> | Yes | The exact table name, in any case | None |
<schema>. | No | The schema of the table, followed by a dot | The 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 |
|-------------|-|-------------|----------------|-----------------|
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.
Related
- SHOW REFERENCES, the opposite direction
- FIND FK, foreign keys by name
- DESCR, how the table name is found
Used in these how-tos
- How do I explore an unfamiliar database in fifteen minutes?
- How do I check what depends on a table before I change it?
Last modified in release 5.5.0.
Found something wrong or unclear on this page? Tell us, with the page address.