外來鍵缺索引檢查指令碼
-
--以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
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28878983/viewspace-2136043/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 10.30 索引,外來鍵索引
- 索引檢查索引
- Linux系統檢查指令碼Linux指令碼
- 記憶體檢查指令碼記憶體指令碼
- 【SCN】Oracle檢查scn值指令碼Oracle指令碼
- MySQL:slave 延遲一列 外來鍵檢查和自增加鎖MySql
- 檢查備份情況的指令碼指令碼
- 外來鍵沒有索引哪些DML操作會被阻塞索引
- 外來鍵欄位未建索引引發的死鎖索引
- Sqlserver自動查詢缺失索引及拼出建立索引的語句的指令碼SQLServer索引指令碼
- 【MySQL】MySQL進階(外來鍵約束、多表查詢、檢視、備份與恢復)MySql
- redis+lua實現指令碼一鍵查詢Redis指令碼
- 比特幣原始碼分析:多執行緒檢查指令碼比特幣原始碼執行緒指令碼
- 主鍵和外來鍵
- sqlserver外來鍵SQLServer
- indexedDB 內鍵與外來鍵Index
- Oracle 指令碼 線上哪些索引從來沒有被使用過Oracle指令碼索引
- 無索引的外來鍵之主表子表DML操作實驗及結論索引
- enq: TM - contention解決之道——外來鍵無索引導致鎖爭用ENQ索引
- 外來鍵約束
- MYSQL的外來鍵MySql
- 一鍵部署指令碼指令碼
- 美團外賣Android Lint程式碼檢查實踐Android
- dba巡檢指令碼指令碼
- mysql巡檢指令碼MySql指令碼
- 通過外來鍵找主鍵
- 生成指令碼,得到所有表的外來鍵約束,然後刪除並重建這些約束指令碼
- 分享實用監控指令碼:使用Shell檢查程式是否存在指令碼
- check_postgres指令碼集檢查資料庫健康情況指令碼資料庫
- 外來鍵的變種
- SQL SERVER巡檢指令碼SQLServer指令碼
- MySQL索引的優缺點MySql索引
- mysql 外來鍵索引入門介紹,為什麼工作中很少有人使用?MySql索引
- 關於外來鍵約束
- mysql建立外來鍵語句MySql
- 為什麼不用外來鍵
- 約束外來鍵筆記筆記
- django外來鍵如何賦值Django賦值
- Docker 指令碼化一鍵部署Docker指令碼