-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcheck_nd_constraints.sql
77 lines (59 loc) · 2.64 KB
/
check_nd_constraints.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
-- check for non deferrable unique/primary constraints that are supported by non unique indexes
-- because of the wide output it is best to spool it
set linesize 200
column owner format a30
break on owner skip 1 on table_name
select con.owner, con.table_name, con.constraint_name, con.constraint_type, index_owner, con.index_name
from dba_indexes ind,
dba_constraints con
where ind.owner = con.index_owner
and ind.index_name = con.index_name
and ind.uniqueness != 'UNIQUE'
and con.constraint_type in ('U', 'P')
and con.deferrable = 'NOT DEFERRABLE'
order by con.owner, con.table_name, con.constraint_name;
clear breaks
column column_name format a30
column column_position format 99 heading CP
column uniqueness format a1 heading U
column index_type format a10
break on owner skip 1 on table_name on index_name on index_type on uniqueness on status
select ind.owner, ind.table_name, ind.index_name, ind.index_type, decode(ind.uniqueness,'UNIQUE', 'Y', 'N') uniqueness,
ind.status, inc.column_name, inc.column_position, ine.column_expression
from dba_indexes ind, dba_ind_columns inc, dba_ind_expressions ine
where ind.owner = inc.index_owner
and ind.index_name = inc.index_name
and inc.index_owner = ine.index_owner(+)
and inc.index_name = ine.index_name(+)
and inc.column_position = ine.column_position(+)
and (ind.owner, ind.index_name) in
( select con.index_owner, con.index_name
from dba_indexes ind,
dba_constraints con
where ind.owner = con.index_owner
and ind.index_name = con.index_name
and ind.uniqueness != 'UNIQUE'
and con.constraint_type in ('U', 'P')
and con.deferrable = 'NOT DEFERRABLE'
)
order by ind.owner, ind.table_name, ind.index_name, inc.column_position;
clear breaks
set long 30
column constraint_name format a30
column constraint_type format a2 heading CT
column column_name format a30
column position format 99 heading CP
break on owner skip 1 on table_name on constraint_name on constraint_type on status
select con.owner, con.table_name, con.constraint_name, con.constraint_type, con.status, col.column_name, col.position
from dba_constraints con,
dba_cons_columns col,
dba_indexes ind
where col.owner = con.owner
and col.constraint_name = con.constraint_name
and ind.owner = con.index_owner
and ind.index_name = con.index_name
and ind.uniqueness != 'UNIQUE'
and con.constraint_type in ('U', 'P')
and con.deferrable = 'NOT DEFERRABLE'
order by con.owner, con.table_name, con.constraint_name, col.position;
clear breaks