温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

外键缺索引检查脚本

发布时间:2020-08-12 08:28:04 来源:ITPUB博客 阅读:168 作者:xypincle 栏目:大数据

  • --以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_Name And b.Status = 'ENABLED' And b.Constraint_Type = 'R' And
  •                b.r_Constraint_Name <> '部门表_PK' And b.r_Constraint_Name = c.Constraint_Name And
  •                c.Table_Name Not 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_Name In (Select 表名 From zlBakTables Union 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_Name And a.Status = 'VALID' And i.Table_Name = b.Table_Name And
  •                            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) = 1 And Cons.Child_Table = Inds.Table_Name)
  • Order By Key_Rows Desc, s.Num_Rows Desc Nulls Last

  • 向AI问一下细节

    免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

    AI