Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> challenge: v7 DBA script --> 8i, 9i, 10g

challenge: v7 DBA script --> 8i, 9i, 10g

From: Mark C. Stock <mcstockX_at_Xenquery>
Date: Thu, 5 Feb 2004 13:27:26 -0500
Message-ID: <NrmdncQvGNWnFr_dRVn-uQ@comcast.com>


ok, smarties...

here's a v7 style DBA script that flattens the columns list of USER_CONS_COLUMNS into comma separated list (part of a set of scripts to check if FK constraints are indexed)

sample output:

TABLE_NAME C CONSTRAINT_NAME COLUMNS

------------ - --------------- --------------------
INV          P SYS_C0016017    ID
INV_ITM      P INV_ITM_PK      INV_ITM, ITM_SEQ
INV_ITM      R SYS_C0016020    INV_ITM

how would you improve it for

[_] 8i?
[_] 9i?
[_] 10g?
[_] 11x?

SELECT table_name

        ,constraint_type
        ,constraint_name
        ,   col1
         || DECODE(col2, NULL, NULL, ', ')
         || col2
         || DECODE(col3, NULL, NULL, ', ')
         || col3
         || DECODE(col4, NULL, NULL, ', ')
         || col4
         || DECODE(col5, NULL, NULL, ', ')
         || col5 AS columns
    FROM (SELECT   table_name

,constraint_type
,constraint_name
,MIN(DECODE(position, 1, column_name)) col1
,MIN(DECODE(position, 2, column_name)) col2
,MIN(DECODE(position, 3, column_name)) col3
,MIN(DECODE(position, 4, column_name)) col4
,MIN(DECODE(position, 5, column_name)) col5
FROM (SELECT ucc.table_name ,uc.constraint_type ,ucc.constraint_name ,ucc.position ,ucc.column_name FROM user_cons_columns ucc ,user_constraints uc WHERE uc.constraint_type IN ('P', 'R') AND uc.constraint_name = ucc.constraint_name AND uc.table_name = ucc.table_name AND uc.owner = ucc.owner) GROUP BY table_name
,constraint_type
,constraint_name)
ORDER BY table_name ,constraint_type ,constraint_name
Received on Thu Feb 05 2004 - 12:27:26 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US