资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

外键缺索引检查脚本


  • --以ZLHIS用户执行
  • Select Child_Table, Foreign_Key,
  •        Cname1|| Nvl2(Cname2, ',' || Cname2, Null) || Nvl2(Cname3, ',' || Cname3, Null) ||
  •         Nvl2(Cname4, ',' || Cname4, Null) || Nvl2(Cname5, ',' || Cname5, Null) || Nvl2(Cname6, ',' || Cname6, Null) ||
  •         Nvl2(Cname7, ',' || Cname7, Null) || Nvl2(Cname8, ',' || Cname8, Null) Columns, Main_Table, Primary_Key,
  •        Decode(p.Table_Name, Null, 0, 1) Key_Rows
  • From(Select Col_Cnt, Main_Table, Primary_Key, Child_Table, Foreign_Key,
  •               Cname1|| Nvl2(Cname2, ',' || Cname2, Null) || Nvl2(Cname3, ',' || Cname3, Null) ||
  •                Nvl2(Cname4, ',' || Cname4, Null) || Nvl2(Cname5, ',' || Cname5, Null) || Nvl2(Cname6, ',' || Cname6, Null) ||
  •                Nvl2(Cname7, ',' || Cname7, Null) || Nvl2(Cname8, ',' || Cname8, Null) As Columns, Cname1, Cname2, Cname3,
  •               Cname4, Cname5, Cname6, Cname7, Cname8
  •        From(Select c.Table_Name As Main_Table, b.r_Constraint_Name As Primary_Key, b.Table_Name As Child_Table,
  •                      b.Constraint_Name As Foreign_Key, Max(Decode(Position, 1, Column_Name, Null)) Cname1,
  •                      Max(Decode(Position, 2, Column_Name, Null)) Cname2, Max(Decode(Position, 3, Column_Name, Null)) Cname3,
  •                      Max(Decode(Position, 4, Column_Name, Null)) Cname4, Max(Decode(Position, 5, Column_Name, Null)) Cname5,
  •                      Max(Decode(Position, 6, Column_Name, Null)) Cname6, Max(Decode(Position, 7, Column_Name, Null)) Cname7,
  •                      Max(Decode(Position, 8, Column_Name, Null)) Cname8, Count(*) Col_Cnt
  •               From User_Cons_Columns A, User_Constraints B, User_Constraints C
  •               Where a.Constraint_Name= b.Constraint_NameAnd b.Status= 'ENABLED' And b.Constraint_Type= 'R' And
  •                b.r_Constraint_Name<> '部门表_PK' And b.r_Constraint_Name= c.Constraint_NameAnd
  •                c.Table_NameNot In (Select 表名 From zlBaseCode)
  •               Group By c.Table_Name, b.Table_Name, b.Constraint_Name, b.r_Constraint_Name)) Cons, User_Tab_Statistics S,
  •     (Select Table_Name
  •        From User_Tables
  •        Where Table_NameIn (Select 表名 From zlBakTablesUnion All Select 表名 From Zlbigtables) Or Table_Name Like'%病人%') P
  • Where Cons.Child_Table= s.Table_Name(+) And Cons.Main_Table= p.Table_Name(+) And Not Exists
  •  (Select 1
  •        From(Select Table_Name,
  •                      Cname1|| Nvl2(Cname2, ',' || Cname2, Null) || Nvl2(Cname3, ',' || Cname3, Null) ||
  •                       Nvl2(Cname4, ',' || Cname4, Null) || Nvl2(Cname5, ',' || Cname5, Null) ||
  •                       Nvl2(Cname6, ',' || Cname6, Null) || Nvl2(Cname7, ',' || Cname7, Null) ||
  •                       Nvl2(Cname8, ',' || Cname8, Null) As Columns
  •               From(Select i.Table_Name, Max(Decode(Column_Position, 1, Column_Name, Null)) Cname1,
  •                             Max(Decode(Column_Position, 2, Column_Name, Null)) Cname2,
  •                             Max(Decode(Column_Position, 3, Column_Name, Null)) Cname3,
  •                             Max(Decode(Column_Position, 4, Column_Name, Null)) Cname4,
  •                             Max(Decode(Column_Position, 5, Column_Name, Null)) Cname5,
  •                             Max(Decode(Column_Position, 6, Column_Name, Null)) Cname6,
  •                             Max(Decode(Column_Position, 7, Column_Name, Null)) Cname7,
  •                             Max(Decode(Column_Position, 8, Column_Name, Null)) Cname8
  •                      From User_Ind_Columns I, User_Indexes A, User_Constraints B
  •                      Where a.Index_Name= i.Index_NameAnd a.Status= 'VALID' And i.Table_Name= b.Table_NameAnd
  •                            b.Constraint_Type= 'R' And b.r_Constraint_Name<> '部门表_PK'
  •                      Group By i.Table_Name, i.Index_Name)) Inds
  •        Where Instr(',' || Inds.Columns, ',' || Cons.Columns) = 1And Cons.Child_Table= Inds.Table_Name)
  • Order By Key_Rows Desc, s.Num_Rows Desc Nulls Last


  • 当前题目:外键缺索引检查脚本
    URL网址:http://cdkjz.cn/article/jhijhs.html
    多年建站经验

    多一份参考,总有益处

    联系快上网,免费获得专属《策划方案》及报价

    咨询相关问题或预约面谈,可以通过以下方式与我们联系

    大客户专线   成都:13518219792   座机:028-86922220