檢查外來鍵是否有索引的指令碼
-
COLUMN COLUMNS format a30 word_wrapped
-
COLUMN tablename format a15 word_wrapped
-
COLUMN constraint_name format a15 word_wrapped
-
SELECT TABLE_NAME,
-
CONSTRAINT_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) COLUMNS
-
FROM (SELECT B.TABLE_NAME,
-
B.CONSTRAINT_NAME,
-
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 (SELECT SUBSTR(TABLE_NAME, 1, 30) TABLE_NAME,
-
SUBSTR(CONSTRAINT_NAME, 1, 30) CONSTRAINT_NAME,
-
SUBSTR(COLUMN_NAME, 1, 30) COLUMN_NAME,
-
POSITION
-
FROM USER_CONS_COLUMNS) A,
-
USER_CONSTRAINTS B
-
WHERE A.CONSTRAINT_NAME = B.CONSTRAINT_NAME
-
AND B.CONSTRAINT_TYPE = 'R'
-
GROUP BY B.TABLE_NAME, B.CONSTRAINT_NAME) CONS
-
WHERE COL_CNT > ALL
-
(SELECT COUNT(*)
-
FROM USER_IND_COLUMNS I
-
WHERE I.TABLE_NAME = CONS.TABLE_NAME
-
AND I.COLUMN_NAME IN (CNAME1, CNAME2, CNAME3, CNAME4, CNAME5,
-
CNAME6, CNAME7, CNAME8)
-
AND I.COLUMN_POSITION <= CONS.COL_CNT
-
GROUP BY I.INDEX_NAME)
- /
-
SET linesize 400;
-
COLUMN OWNER format a10 word_wrapped
-
COLUMN COLUMNS format a30 word_wrapped
-
COLUMN TABLE_NAME format a15 word_wrapped
-
COLUMN CONSTRAINT_NAME format a40 word_wrapped
-
SELECT OWNER,
-
TABLE_NAME,
-
CONSTRAINT_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) COLUMNS
-
FROM (SELECT B.OWNER,B.TABLE_NAME,
-
B.CONSTRAINT_NAME,
-
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 (SELECT SUBSTR(TABLE_NAME, 1, 30) TABLE_NAME,
-
SUBSTR(CONSTRAINT_NAME, 1, 30) CONSTRAINT_NAME,
-
SUBSTR(COLUMN_NAME, 1, 30) COLUMN_NAME,
-
POSITION
-
FROM DBA_CONS_COLUMNS WHERE OWNER NOT IN ('SYS','SYSTEM','SYSMAN','HR','OE','EXFSYS','DBSNMP','MDSYS','OLAPSYS','SCOTT','EXFSYS','SH','PM','CTXSYS')) A,
-
DBA_CONSTRAINTS B
-
WHERE A.CONSTRAINT_NAME = B.CONSTRAINT_NAME
-
AND B.CONSTRAINT_TYPE = 'R'
-
GROUP BY B.OWNER,B.TABLE_NAME, B.CONSTRAINT_NAME) CONS
-
WHERE COL_CNT > ALL
-
(SELECT COUNT(*)
-
FROM DBA_IND_COLUMNS I
-
WHERE I.TABLE_NAME = CONS.TABLE_NAME AND I.TABLE_OWNER=CONS.OWNER
-
AND I.COLUMN_NAME IN (CNAME1, CNAME2, CNAME3, CNAME4, CNAME5,
-
CNAME6, CNAME7, CNAME8)
-
AND I.COLUMN_POSITION <= CONS.COL_CNT
-
GROUP BY I.INDEX_NAME)
- /
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29254281/viewspace-1176022/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 10.30 索引,外來鍵索引
- 外來鍵沒有索引哪些DML操作會被阻塞索引
- shell指令碼死迴圈檢查是否有特定的路由,若不存在進行增加操作指令碼路由
- 分享實用監控指令碼:使用Shell檢查程式是否存在指令碼
- Linux中檢視指令碼程式是否存在的命令!Linux指令碼
- 索引檢查索引
- Linux系統檢查指令碼Linux指令碼
- 記憶體檢查指令碼記憶體指令碼
- 檢查備份情況的指令碼指令碼
- Oracle 指令碼 線上哪些索引從來沒有被使用過Oracle指令碼索引
- 如何使用 Shell 指令碼來檢視多個伺服器的埠是否開啟?指令碼伺服器
- Sqlserver自動查詢缺失索引及拼出建立索引的語句的指令碼SQLServer索引指令碼
- 【SCN】Oracle檢查scn值指令碼Oracle指令碼
- 檢查陣列中是否有重複項陣列
- 外來鍵欄位未建索引引發的死鎖索引
- MySQL:slave 延遲一列 外來鍵檢查和自增加鎖MySql
- jquery幾種用來檢查checkbox是否選中的方法jQuery
- MYSQL的外來鍵MySql
- 【MySQL】MySQL進階(外來鍵約束、多表查詢、檢視、備份與恢復)MySql
- redis+lua實現指令碼一鍵查詢Redis指令碼
- 無索引的外來鍵之主表子表DML操作實驗及結論索引
- 比特幣原始碼分析:多執行緒檢查指令碼比特幣原始碼執行緒指令碼
- 外來鍵的變種
- 檢查型別是否溢位型別
- 主鍵和外來鍵
- sqlserver外來鍵SQLServer
- 生成指令碼,得到所有表的外來鍵約束,然後刪除並重建這些約束指令碼
- 大家有沒有關於 Python 執行起來不錯的程式碼檢查工具?用於 CICD 裡面的靜態程式碼檢查Python
- indexedDB 內鍵與外來鍵Index
- 如何檢查域名解析是否生效?
- php檢查某個日期是否有效PHP
- 如何檢查是否物理伺服器?伺服器
- dfs檢測是否有環的優化優化
- 新的主鍵和外來鍵的語法
- enq: TM - contention解決之道——外來鍵無索引導致鎖爭用ENQ索引
- 外來鍵約束
- 一鍵部署指令碼指令碼
- 美團外賣Android Lint程式碼檢查實踐Android
- dba巡檢指令碼指令碼