KEY_COLUMN_USAGE 表描述了哪些键列具有约束。该表不提供关于函数键部分的信息,因为它们是表达式,而该表只提供关于列的信息。The KEY_COLUMN_USAGE table describes
which key columns have constraints. This table provides no
information about functional key parts because they are
expressions and the table provides information only about columns.
KEY_COLUMN_USAGE 表具有以下列:The KEY_COLUMN_USAGE table has these
columns:
CONSTRAINT_CATALOGCONSTRAINT_CATALOG约束所属的目录名称。该值始终为
def。The name of the catalog to which the constraint belongs. This value is alwaysdef.CONSTRAINT_SCHEMACONSTRAINT_SCHEMA约束所属的模式(数据库)名称。The name of the schema (database) to which the constraint belongs.
CONSTRAINT_NAMECONSTRAINT_NAME约束的名称。The name of the constraint.
TABLE_CATALOG表所属的目录名称。该值始终为
def。The name of the catalog to which the table belongs. This value is alwaysdef.TABLE_SCHEMA表所属的模式(数据库)名称。The name of the schema (database) to which the table belongs.
TABLE_NAMETABLE_NAME具有约束的表的名称。The name of the table that has the constraint.
COLUMN_NAMECOLUMN_NAME具有约束的列的名称。The name of the column that has the constraint.
如果约束是外键,那么这是外键的列,而不是外键引用的列。If the constraint is a foreign key, then this is the column of the foreign key, not the column that the foreign key references.
ORDINAL_POSITION列在约束中的位置,而不是列在表中的位置。列的位置编号从 1 开始。The column's position within the constraint, not the column's position within the table. Column positions are numbered beginning with 1.
POSITION_IN_UNIQUE_CONSTRAINT对于唯一约束和主键约束为
NULL。对于外键约束,此列是被引用表中键的序号位置。NULLfor unique and primary-key constraints. For foreign-key constraints, this column is the ordinal position in key of the table that is being referenced.REFERENCED_TABLE_SCHEMA约束引用的架构名称。The name of the schema referenced by the constraint.
REFERENCED_TABLE_NAME约束引用的表名称。The name of the table referenced by the constraint.
REFERENCED_COLUMN_NAME约束引用的列名称。The name of the column referenced by the constraint.
假设有两个表名为 t1 和 t3,它们具有以下定义:Suppose that there are two tables name t1 and
t3 that have the following definitions:
CREATE TABLE t1
(
s1 INT,
s2 INT,
s3 INT,
PRIMARY KEY(s3)
) ENGINE=InnoDB;
CREATE TABLE t3
(
s1 INT,
s2 INT,
s3 INT,
KEY(s1),
CONSTRAINT CO FOREIGN KEY (s2) REFERENCES t1(s3)
) ENGINE=InnoDB;
对于这两个表,KEY_COLUMN_USAGE 表有两行记录:For those two tables, the
KEY_COLUMN_USAGE table has two rows:
一行记录的
CONSTRAINT_NAME='PRIMARY',TABLE_NAME='t1',COLUMN_NAME='s3',ORDINAL_POSITION=1,POSITION_IN_UNIQUE_CONSTRAINT=NULL。One row withCONSTRAINT_NAME='PRIMARY',TABLE_NAME='t1',COLUMN_NAME='s3',ORDINAL_POSITION=1,POSITION_IN_UNIQUE_CONSTRAINT=NULL.对于
NDB:此值始终为NULL。ForNDB: This value is alwaysNULL.一行,
CONSTRAINT_NAME='CO',TABLE_NAME='t3',COLUMN_NAME='s2',ORDINAL_POSITION=1,POSITION_IN_UNIQUE_CONSTRAINT=1。One row withCONSTRAINT_NAME='CO',TABLE_NAME='t3',COLUMN_NAME='s2',ORDINAL_POSITION=1,POSITION_IN_UNIQUE_CONSTRAINT=1.