information_schema.key_column_usage 表可以查看索引列上的约束;

1、information_schema.key_column_usage 的常用列:

  1、constraint_catalog              :约束类型这个永远是def

  2、constraint_schema              :约束所在的数据库名

  3、constraint_name               :约束名

  4、table_catalog                 :表类型这个永远是def

  5、table_schema                  :表所在的数据库名

  6、column_name                  :索引所在的列名

  7、referenced_table_schema           :被引用表所在的数据库名

  8、referenced_table_name            :被引用的表名

  9、referenced_column_name           :被引用表的列名

2、例子:

通过information_schema.key_column_usage表来查看外键引用关系

  1、创建有主外键关系的表

create table teacher(
id int not null auto_increment,
name varchar(16) not null,
primary key pk_teacher(id)
) engine=innodb default char set utf8; create table student(
id int not null auto_increment,
name varchar(16) not null,
teacher_id int not null,
constraint pk_student__id primary key(id),
constraint fk_stuent__teacher_id foreign key(teacher_id) references teacher(id)
) engine=innodb default char set utf8;

  2、查看索引列上的约束

select * from KEY_COLUMN_USAGE where table_schema='tempdb' \G
*************************** 1. row ***************************
CONSTRAINT_CATALOG: def
CONSTRAINT_SCHEMA: tempdb
CONSTRAINT_NAME: PRIMARY
TABLE_CATALOG: def
TABLE_SCHEMA: tempdb
TABLE_NAME: student
COLUMN_NAME: id
ORDINAL_POSITION: 1
POSITION_IN_UNIQUE_CONSTRAINT: NULL
REFERENCED_TABLE_SCHEMA: NULL
REFERENCED_TABLE_NAME: NULL
REFERENCED_COLUMN_NAME: NULL
*************************** 2. row ***************************
CONSTRAINT_CATALOG: def
CONSTRAINT_SCHEMA: tempdb
CONSTRAINT_NAME: fk_stuent__teacher_id
TABLE_CATALOG: def
TABLE_SCHEMA: tempdb
TABLE_NAME: student
COLUMN_NAME: teacher_id
ORDINAL_POSITION: 1
POSITION_IN_UNIQUE_CONSTRAINT: 1
REFERENCED_TABLE_SCHEMA: tempdb
REFERENCED_TABLE_NAME: teacher
REFERENCED_COLUMN_NAME: id
*************************** 3. row ***************************
CONSTRAINT_CATALOG: def
CONSTRAINT_SCHEMA: tempdb
CONSTRAINT_NAME: PRIMARY
TABLE_CATALOG: def
TABLE_SCHEMA: tempdb
TABLE_NAME: teacher
COLUMN_NAME: id
ORDINAL_POSITION: 1
POSITION_IN_UNIQUE_CONSTRAINT: NULL
REFERENCED_TABLE_SCHEMA: NULL
REFERENCED_TABLE_NAME: NULL
REFERENCED_COLUMN_NAME: NULL

information_schema.key_column_usage 学习的更多相关文章

  1. information_schema.referential_constraints 学习

    information_schema.referential_constraints 表用于查看外键约束 1.information_schema.referential_constraints表的常 ...

  2. information_schema.profiling学习

    information_schema.profiling可以用来分析每一条SQL在它执行的各个阶段的用时,注意这个表是session 级的,也就是说如果session1 开启了它:session2没有 ...

  3. information_schema.optimizer_trace学习

    information_schema.optimizer_trace 用于追踪优化器的优化过程:通常来说这张表中是没有数据的,要想开户追踪要把 @@session.optimizer_trace='e ...

  4. information_schema.triggers 学习

    mysql实例中的每一个trigger 对应到information_schema.triggers 中有一行 1.information_schema.triggers 表的常用列: 1.trigg ...

  5. information_schema.routines 学习

    information_schema.routines 用户查看mysql中的routine信息 1.information_schema.routines 表中的常用列: 1.

  6. information_schema.events 学习

    information_schema.events 表保存了整个mysql实例中的event 信息 1.常用列: 1.event_catalog :永远是def 2.event_schema :eve ...

  7. information_schema.engines学习

    当前mysql实例的存储引擎信息可以从information_schema.engines 中查询到 例子: mysql> select * from information_schema.en ...

  8. information_schema.column_privileges 学习

    mysql 的授权是分层次的 实例级 | 库级 | 表级 | 列级 而这些授权信息被保存在了mysql.user | mysql.db | mysql.tables_priv | mysql.colu ...

  9. information_schema.columns 学习

    每一个表中的每一列都会在information_schema.columns表中对应一行 1.informaiton_schema.columns 常用列: 1.table_catalog :不管是t ...

随机推荐

  1. excel筛选两列值是否相同,如果相同返回第三列值

    见图:

  2. ps存jpeg,格式保存的时候为什么选择“基线”

    jpeg是印前和网页设计常用的格式,最大好处就是能很大程度上压缩图像大小. 在ps中将图片保存为jpeg格式的时候会出现以下选项: 其中:图像选项都很熟悉,是关于图像质量的:而格式选项的用途主要是针对 ...

  3. 行为级和RTL级的区别(转)

    转自:http://hi.baidu.com/renmeman/item/5bd83496e3fc816bf14215db RTL级,registertransferlevel,指的是用寄存器这一级别 ...

  4. hdu 1535 Invitation Cards

    http://acm.hdu.edu.cn/showproblem.php?pid=1535 这道题两遍spfa,第一遍sfpa之后,重新建图,所有的边逆向建边,再一次spfa就可以了. #inclu ...

  5. eclipse打开文件位置Open Explorer 插件

    ,OpenExplorer插件可以满足这个功能,可以到https://github.com/samsonw/OpenExplorer/downloads下载最新版本,将jar包放到eclipse的pl ...

  6. java cglib动态代理原理及样例

     cglib动态代理: http://blog.csdn.net/xiaohai0504/article/details/6832990 一.原理 代理为控制要访问的目标对象提供了一种途径.当访问 ...

  7. LeetCode C++ 解题报告

    自己做得LeetCode的题解,使用C++语言. 说明:大多数自己做得,部分参考别人的思路,仅供参考; GitHub地址:https://github.com/amazingyyc/The-Solut ...

  8. UVa10815.Andy's First Dictionary

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. Android NDK R9d 安装

    NDK是一个工具集,可让您实现您的应用程序使用本机代码的语言,如C和C + +.Android NDK 是在SDK前面又加上了“原生”二字,即Native Development Kit,因此又被Go ...

  10. PC--CSS命名

    头:header内 容:container尾:footer导航:nav侧栏:sidebar栏目:column页 面外围控制整体布局宽度:wrapper左右中:left right center登录条: ...