该脚本用于列出在子表上没有对应索引的外键,没有索引可能引发额外的表锁:

"You should almost always index foreign keys.
The only exception is when the matching unique or primary key is never updated or deleted."When a foreign key is unindexed, DML on the parent primary key results in a share row exclusive table lock
(or share-subexclusive table lock, SSX) on the child table, preventing DML from other transactions
against the child table. If the DML affects several rows in the parent table, the lock on the child table
is obtained and released immediately for each row in turn. Despite the speed of the lock-release process,
this can cause significant amounts of contention on the child table during periods of
heavy update/delete activity on the parent table.When a foreign key is indexed, DML on the parent primary key results in a row share table lock
(or subshare table lock, SS) on the child table. This type of lock prevents other transactions
from issuing whole table locks on the child table, but does not block DML on either the parent or
the child table. Only the rows relating to the parent primary key are locked in the child table.

Script:

REM  List foreign keys with no matching index on child table - causes locksset linesize 150;col owner for a20;
col COLUMN_NAME for a20;SELECT c.owner,c.constraint_name,c.table_name,cc.column_name,c.statusFROM dba_constraints c, dba_cons_columns ccWHERE c.constraint_type = 'R'AND c.owner NOT IN('SYS','SYSTEM','SYSMAN','EXFSYS','WMSYS','OLAPSYS','OUTLN','DBSNMP','ORDSYS','ORDPLUGINS','MDSYS','CTXSYS','AURORA$ORB$UNAUTHENTICATED','XDB','FLOWS_030000','FLOWS_FILES')AND c.owner = cc.ownerAND c.constraint_name = cc.constraint_nameAND NOT EXISTS(SELECT 'x'FROM dba_ind_columns icWHERE     cc.owner = ic.table_ownerAND cc.table_name = ic.table_nameAND cc.column_name = ic.column_nameAND cc.position = ic.column_positionAND NOT EXISTS(SELECT owner, index_nameFROM dba_indexes iWHERE     i.table_owner = c.ownerAND i.index_Name = ic.index_nameAND i.owner = ic.index_ownerAND (i.status = 'UNUSABLE'OR i.partitioned = 'YES'AND EXISTS(SELECT 'x'FROM dba_ind_partitions ipWHERE status ='UNUSABLE'AND ip.index_owner =i.ownerAND ip.index_Name =i.index_nameUNION ALLSELECT 'x'FROM dba_ind_subpartitions ispWHERE status ='UNUSABLE'AND isp.index_owner =i.ownerAND isp.index_Name =i.index_name))))
ORDER BY 1, 2
/

Script:列出数据库中子表上没有对应索引的外键相关推荐

  1. mysql建表时外检怎么创建_MySQL创建表时加入的约束以及外键约束的的意义

    1,创建表时加入的约束 a) 非空约束,not null b) 唯一约束,unique c) 主键约束,primary key d) 外键约束,foreign key 1,非空约束,针对某个字段设置其 ...

  2. Spring Data JAP框架处理表关系的步骤(一对一外键关联

    Spring Data JAP框架处理表关系的步骤: 1)确定表和表之间的关系 2)对应表创建实体类 3)在实体类配置注解关联关系 4)测试 一对一表关系的实现方案(外键关联: 1 在Customer ...

  3. oracle_sqlserver和mysql获取表外键的方法_mysql、sqlserver、oracle三种数据库维护索引、外键、字段语法总结...

    mysql.sqlserver.oracle三种数据库维护索引.外键.字段语法总结 1.     MYSQL数据库 1)    创建索引 CREATE INDEX index_name ON tabl ...

  4. datetime建立索引有用吗_超全的数据库建表、SQL、索引规范

    背景 因为工作岗位的原因,负责制定了关于后端组数据库的规约规范,作为所有产品线的规范,历经几版的修改,最终形成下边的文本,规范在整个后端执行也有大半年的时间,对于整个团队在开发阶段就减少不恰当的建表语 ...

  5. oracle数据库(表、视图、索引、事务)

    1.视图与表的区别 1) 表需要占用磁盘空间,视图不用,视图作为数据对象存储在oracle中. 2) 视图不能添加索引,查询视图效率会比添加索引的表慢一点点 3) 视图可以简化复杂查询 4) 视图利于 ...

  6. 超全的数据库建表、SQL、索引规范

    背景 因为工作岗位的原因,负责制定了关于后端组数据库的规约规范,作为所有产品线的规范,历经几版的修改,最终形成下边的文本,规范在整个后端执行也有大半年的时间,对于整个团队在开发阶段就减少不恰当的建表语 ...

  7. django不修改数据库创外键_Django——model(建表,增删改查,外键,多对多)

    数据库操作 dbfirst:数据库优先 codefirst(ORM):代码优先,sqlalchemy和DJango都是用的这种 创建表 a.在app下的models.py中,创建类 from djan ...

  8. mysql用外键链接两个表_可能做一个MySQL外键的两个可能的表之一?

    你所描述的是多态关联.也就是说,"外键"列包含必须存在于一组目标表之一中的id值.通常,目标表以某种方式相关,例如一些常见的数据超类的实例.您还需要外键列旁边的另一列,以便在每行上 ...

  9. 如何在oracle中查询所有用户表的表名、主键名称、索引、外键等

    使用select   *   from   user_tables   可以查询出所有的用户表. 查所有用户的表在all_tables 主键名称.外键在all_constraints 索引在all_i ...

最新文章

  1. pgadmin使用教程
  2. 刚才遇到了关于C#使用外部DLL函数上的char*的问题。
  3. 软件项目周报_软件产品研发流程
  4. php中echo有哪些,php中echo和print有什么区别
  5. [Aaronyang] 写给自己的WPF4.5 笔记17[Page实现页面导航]
  6. 服务器导流板的作用,前保险杠下导流板的作用是什么?
  7. 计算机网络的创新创业计划书,互联网创新创业计划书.doc
  8. 教学案例分析 计算机应用,计算机教学案例分析
  9. 陈俊龙:从深度强化学习到宽度强化学习—结构,算法,机遇及挑战
  10. PDF如何裁剪页面,PDF裁剪页面的方法
  11. 笔记本电池冲不进电或不存电的修复方法
  12. 小米node2红外_智能家居之一:小米人体传感器2使用体验
  13. FreeRTOS软件定时器 基于STM32
  14. 如何实现双因素认证?
  15. SQL Server 学习笔记——T-SQL
  16. Geom error原因以及解决办法
  17. 美剧中的英文粗语脏话知多少?
  18. 51单片机的频率计设计
  19. tsmc 7nm工艺下用做syncCell的stdCell介绍
  20. 基于51单片机的步进电机驱动,亲测无误

热门文章

  1. java实现随机字母数字验证码
  2. 河北师范大学计算机科学与技术研究生好考吗,河北师范大学计算机科学与技术怎么样...
  3. c语言 获取文件名的相对路径,c – 如何获取对应于给予dlopen的相对路径的绝对库文件名?...
  4. [Spring 深度解析]第1章 Java基础
  5. 就是这么牛逼,利用Python绘制炫酷专业插图就是这么简单
  6. linux挂载home分区,Linux(CentOS6) 调整 /home 挂载 分区大小
  7. 教程:1、Linux简介
  8. python图形缝隙填充_Python,如何缝合图像哪些重叠区域?
  9. sar极化想干矩阵_用于PolSAR图像分类的极化卷积网络
  10. 模型与logit_互助问答第33期:条件logit模型相关问题