-
Notifications
You must be signed in to change notification settings - Fork 7
/
Consulta Diccionario de datos.sql
94 lines (92 loc) · 4.32 KB
/
Consulta Diccionario de datos.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
select col.owner as schema_name,
col.table_name,
col.column_name,
col.data_type,
col.data_length,
col.nullable,
comm.comments,
nvl(pk.primary_key,fk.foreign_key) as constraint_1,
nvl(nvl(pk.constraint_name,fk.constraint_name),uk.constraint_name) as constraint_name
from all_tables tab
inner join all_tab_columns col
on col.owner = tab.owner
and col.table_name = tab.table_name
left join all_col_comments comm
on col.owner = comm.owner
and col.table_name = comm.table_name
and col.column_name = comm.column_name
left join (select constr.owner,
col_const.table_name,
col_const.column_name,
'PK' primary_key,
constr.constraint_name
from all_constraints constr
inner join all_cons_columns col_const
on constr.constraint_name = col_const.constraint_name
and col_const.owner = constr.owner
where constr.constraint_type = 'P') pk
on col.table_name = pk.table_name
and col.column_name = pk.column_name
and col.owner = pk.owner
left join (select constr.owner,
col_const.table_name,
col_const.column_name,
'FK' foreign_key,
constr.constraint_name
from all_constraints constr
inner join all_cons_columns col_const
on constr.constraint_name = col_const.constraint_name
and col_const.owner = constr.owner
where constr.constraint_type = 'R'
group by constr.owner,
col_const.table_name,
col_const.column_name,
constr.constraint_name) fk
on col.table_name = fk.table_name
and col.column_name = fk.column_name
and col.owner = fk.owner
left join (select constr.owner,
col_const.table_name,
col_const.column_name,
'UK' unique_key,
constr.constraint_name constraint_name
from all_constraints constr
inner join all_cons_columns col_const
on constr.constraint_name = col_const.constraint_name
and constr.owner = col_const.owner
where constr.constraint_type = 'U'
union
select ind.owner,
col_ind.table_name,
col_ind.column_name,
'UK' unique_key,
col_ind.index_name constraint_name
from all_indexes ind
inner join all_ind_columns col_ind
on ind.index_name = col_ind.index_name
where ind.uniqueness = 'UNIQUE') uk
on col.table_name = uk.table_name
and col.column_name = uk.column_name
and col.owner = uk.owner
left join (select constr.owner,
col_const.table_name,
col_const.column_name,
'Check' check_constraint
from all_constraints constr
inner join all_cons_columns col_const
on constr.constraint_name = col_const.constraint_name
and col_const.owner = constr.owner
where constr.constraint_type = 'C'
group by constr.owner,
col_const.table_name,
col_const.column_name) check_const
on col.table_name = check_const.table_name
and col.column_name = check_const.column_name
and col.owner = check_const.owner
where col.owner in ('LEO', 'CR','YEISON','ASH')
and col.table_name ='BOOKS'
-- and col.owner = 'HR'
-- and lower(tab.table_name) like '%'
order by col.owner,
col.table_name,
col.column_name;