Note
This view was introduced in OceanBase Database V1.4.
Purpose
The information_schema.KEY_COLUMN_USAGE view displays the information about constraints on columns.
Columns
| Column | Type | Nullable? | Description |
|---|---|---|---|
| CONSTRAINT_CATALOG | varchar(3) | NO | The catalog. The value of this column is always def. |
| CONSTRAINT_SCHEMA | varchar(128) | NO | The name of the database |
| CONSTRAINT_NAME | varchar(7) | NO | The name of the constraint. The value of this column is PRIMARY, the column name, or the foreign key name. |
| TABLE_CATALOG | varchar(3) | NO | The name of the catalog to which the table belongs. |
| TABLE_SCHEMA | varchar(128) | NO | The name of the database. |
| TABLE_NAME | varchar(256) | NO | The name of the table. |
| COLUMN_NAME | varchar(128) | NO | The name of the column. |
| ORDINAL_POSITION | bigint(20) | NO | The serial number of the column in the table. |
| POSITION_IN_UNIQUE_CONSTRAINT | null | NO | At present, the value of this column is NULL by default. |
| REFERENCED_TABLE_SCHEMA | varchar(128) | NO | At present, the value of this column is NULL by default. |
| REFERENCED_TABLE_NAME | varchar(256) | NO | At present, the value of this column is NULL by default. |
| REFERENCED_COLUMN_NAME | varchar(128) | NO | At present, the value of this column is NULL by default. |
Sample query
Query the constraint information of the key in the tbl4 table.
obclient [oceanbase]> SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE TABLE_NAME='tbl4';
The query result is as follows:
+--------------------+-------------------+----------------------------+---------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+
| CONSTRAINT_CATALOG | CONSTRAINT_SCHEMA | CONSTRAINT_NAME | TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | COLUMN_NAME | ORDINAL_POSITION | POSITION_IN_UNIQUE_CONSTRAINT | REFERENCED_TABLE_SCHEMA | REFERENCED_TABLE_NAME | REFERENCED_COLUMN_NAME |
+--------------------+-------------------+----------------------------+---------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+
| def | infotest | tbl4_OBFK_1736909788672362 | def | infotest | tbl4 | col2 | 1 | 1 | infotest | tbl2 | col1 |
+--------------------+-------------------+----------------------------+---------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+
1 row in set