This is a read-only copy of the MariaDB Knowledgebase generated on 2024-12-22. For the latest, interactive version please visit https://mariadb.com/kb/.

Information Schema KEY_COLUMN_USAGE Table

The Information Schema KEY_COLUMN_USAGE table shows which key columns have constraints.

It contains the following columns:

ColumnDescription
CONSTRAINT_CATALOGAlways def.
CONSTRAINT_SCHEMADatabase name of the constraint.
CONSTRAINT_NAMEName of the constraint (PRIMARY for the primary key).
TABLE_CATALOGAlways #def.
TABLE_SCHEMADatabase name of the column constraint.
TABLE_NAMETable name of the column constraint.
COLUMN_NAMEColumn name of the constraint.
ORDINAL_POSITIONPosition of the column within the constraint.
POSITION_IN_UNIQUE_CONSTRAINTFor foreign keys, the position in the unique constraint.
REFERENCED_TABLE_SCHEMAFor foreign keys, the referenced database name.
REFERENCED_TABLE_NAMEFor foreign keys, the referenced table name.
REFERENCED_COLUMN_NAMEFor foreign keys, the referenced column name.

Example

SELECT * FROM information_schema.KEY_COLUMN_USAGE LIMIT 1 \G
********************** 1. row **********************
           CONSTRAINT_CATALOG: def
            CONSTRAINT_SCHEMA: my_website
              CONSTRAINT_NAME: PRIMARY
                TABLE_CATALOG: def
                 TABLE_SCHEMA: users
                  COLUMN_NAME: user_id
             ORDINAL_POSITION: 1
POSITION_IN_UNIQUE_CONSTRAINT: NULL
      REFERENCED_TABLE_SCHEMA: NULL
        REFERENCED_TABLE_NAME: NULL
       REFERENCED_COLUMN_NAME: NULL

See Also

Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.