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. extern "c"用法

    在Windows驱动开发中,如果是使用C++开发的,那么必须在有些关键函数钱加extern c 的关键词,否则编译出来的函数,跟C语言编译的函数不同,导致驱动程序不能 被有效识别. 最关键的是Driv ...

  2. NSIS脚本根据操作系统版本动态决定默认安装目录

    问题描述: 因为windows XP和windows 7的program files不同(有program files(x86)),所以需要动态根据系统的位数设置默认安装目录 References: ...

  3. mutate 转换

    zjtest7-frontend:/usr/local/logstash-2.3.4/config# cat geoip.conf input {stdin {} } filter { geoip { ...

  4. 【转】win32,win64编程永恒;语言编程需要注意的64位和32机器的区别

    原文网址:http://www.cnblogs.com/kex1n/archive/2010/10/06/1844737.html 一.数据类型特别是int相关的类型在不同位数机器的平台下长度不同.C ...

  5. Sum Root to Leaf Numbers 解答

    Question Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent ...

  6. Sqrt(x) 解答

    Question Implement int sqrt(int x). Compute and return the square root of x. Solution 1 -- O(log n) ...

  7. ofbiz安装优化

    一. 1.安装jdk 2.安装数据库 3.安装ant yum install ant 4.编译启动ofbiz cd /ofbiz目录下 ant run-install ./startofbiz.sh ...

  8. BZOJ 4541 【HNOI2016】 矿区

    题目链接:矿区 这道题去年暑假就想写了,但是一直拖拉,以至于现在才来写这道题.以前一直在刻意回避几何类的题目,但到了现在这个时候,已经没有什么好害怕的了. 正巧今天神犇\(xzy\)讲了这道题,那我就 ...

  9. Angular Textarea 高度自动变化

    很多前端开发的朋友可能都会遇到textarea 输入框的高度不能自动随着用户的输入变化的问题,今儿小生也遇到了, 并通过网络上的信息解决了这个问题,于是将解决方法贴上,以作备忘. directiveA ...

  10. ToString()和Convert.ToString()的区别

    ToString()和Convert.ToString()的区别 一般情况下,这两种方法都可以通用,但是当返回的数据类型中有可能出现null值时如果调用ToString方法了,就会返回NullRefe ...