information_schema.referential_constraints 学习
2017-07-30 22:27
399 查看
information_schema.referential_constraints 表用于查看外键约束 1、information_schema.referential_constraints表的常用列: 1、constraint_schema :约束(外键)所在的库名 2、constraint_name :约束名(外键名) 3、unique_constraint_schema :被引用约束所在库名 4、unique_constraint_name :被引用约束名 2、例子: 1、定义一对有外键约束的表:
create table teacher( id int not null auto_increment, name varchar(4), constraint pk__teacher primary key(id), constraint ix__teacher__name unique index (name)) engine=innodb default char set utf8; create table student( id int not null auto_increment, name varchar(4), teacher_id int not null, teacher_name varchar(4), constraint pk__student primary key(id), constraint fk__student__id foreign key (teacher_id ) references teacher(id), constraint fk__student__teacher_name foreign key (teacher_name) references teacher(name) on delete no action on update cascade) engine=innodb default char set utf8;2、查看外键约束
select * from information_schema.referential_constraints \G *************************** 1. row *************************** CONSTRAINT_CATALOG: def CONSTRAINT_SCHEMA: tempdb CONSTRAINT_NAME: fk__student__id UNIQUE_CONSTRAINT_CATALOG: def UNIQUE_CONSTRAINT_SCHEMA: tempdb UNIQUE_CONSTRAINT_NAME: PRIMARY MATCH_OPTION: NONE UPDATE_RULE: RESTRICT DELETE_RULE: RESTRICT TABLE_NAME: student REFERENCED_TABLE_NAME: teacher *************************** 2. row *************************** CONSTRAINT_CATALOG: def CONSTRAINT_SCHEMA: tempdb CONSTRAINT_NAME: fk__student__teacher_name UNIQUE_CONSTRAINT_CATALOG: def UNIQUE_CONSTRAINT_SCHEMA: tempdb UNIQUE_CONSTRAINT_NAME: ix__teacher__name MATCH_OPTION: NONE UPDATE_RULE: CASCADE DELETE_RULE: NO ACTION TABLE_NAME: student REFERENCED_TABLE_NAME: teacher
相关文章推荐
- information_schema.referential_constraints 学习
- information_schema.character_sets 学习
- information_schema.key_column_usage 学习
- information_schema系统表——TABLE_CONSTRAINTS
- 36.笔记 MySQL学习——借助INFORMATION_SCHEMA获取元数据
- information_schema.column_privileges 学习
- information_schema.events 学习
- information_schema.columns 学习
- mysql中元数据库information_schema学习之TABLES表
- information_schema.collations 学习
- information_schema.routines 学习
- information_schema.partitions 学习
- MySQL学习系列之关于information_schema(一)
- information_schema.triggers 学习
- information_schema.collation_character_set_applicability 学习
- 探讨SQL利用INFORMATION_SCHEMA系统视图如何获取表的主外键信息
- MySQL中information_schema是什么
- PostgreSQL学习手册(模式Schema)
- MySQL的information_schema
- 关于MySQL中的information_schema