SQL - Referenzen auf eine Tabelle ermitteln
Damit das Einfügen in eine Tabelle der DIRECT LOAD erfolgen kann, dürfen keine Referenzen auf diese Tabelle aktiv sein.
Zum prüfen, welche Referenzen es gibt und welchen Status diese haben:
-- Tabelle wird referenziert von...
Select c1.owner, c1.constraint_name, c1.table_name, c1.r_owner, c1.r_constraint_name, c2.table_name r_table_name,
c1.delete_rule, c1.status, c1.DEFERRABLE, c1.DEFERRED, c1.validated, c2.constraint_type r_constraint_type
FROM sys.ALL_CONSTRAINTS c1, sys.ALL_CONSTRAINTS c2
WHERE c1.constraint_type = 'R'
AND c2.constraint_type IN ('P', 'U')
AND c2.owner = 'mySchema'
AND c2.table_name = 'myTable'
AND c1.r_owner = c2.owner
AND c1.r_constraint_Name = c2.constraint_name
order by 1,3;
Select 'alter table '||c1.owner||'.'||c1.table_name||' disable constraint '||c1.constraint_name||';' Txt
FROM sys.ALL_CONSTRAINTS c1, sys.ALL_CONSTRAINTS c2
WHERE c1.constraint_type = 'R'
AND c2.constraint_type IN ('P', 'U')
AND c2.owner = 'mySchema'
AND c2.table_name = 'myTable'
AND c1.r_owner = c2.owner
AND c1.r_constraint_Name = c2.constraint_name
order by 1;
Zum prüfen, welche Referenzen es gibt und welchen Status diese haben:
-- Tabelle wird referenziert von...
Select c1.owner, c1.constraint_name, c1.table_name, c1.r_owner, c1.r_constraint_name, c2.table_name r_table_name,
c1.delete_rule, c1.status, c1.DEFERRABLE, c1.DEFERRED, c1.validated, c2.constraint_type r_constraint_type
FROM sys.ALL_CONSTRAINTS c1, sys.ALL_CONSTRAINTS c2
WHERE c1.constraint_type = 'R'
AND c2.constraint_type IN ('P', 'U')
AND c2.owner = 'mySchema'
AND c2.table_name = 'myTable'
AND c1.r_owner = c2.owner
AND c1.r_constraint_Name = c2.constraint_name
order by 1,3;
Zum Abschalten (nicht Löschen!):
-- erzeugt SQL zum Abschalten der Referenzen:Select 'alter table '||c1.owner||'.'||c1.table_name||' disable constraint '||c1.constraint_name||';' Txt
FROM sys.ALL_CONSTRAINTS c1, sys.ALL_CONSTRAINTS c2
WHERE c1.constraint_type = 'R'
AND c2.constraint_type IN ('P', 'U')
AND c2.owner = 'mySchema'
AND c2.table_name = 'myTable'
AND c1.r_owner = c2.owner
AND c1.r_constraint_Name = c2.constraint_name
order by 1;
Zum wieder Einschalten:
-- erzeugt SQL zum Einschalten der Referenzen, ohne Validierung:
Select 'alter table '||c1.owner||'.'||c1.table_name||' enable novalidate constraint '||c1.constraint_name||';' Txt
FROM sys.ALL_CONSTRAINTS c1, sys.ALL_CONSTRAINTS c2
WHERE c1.constraint_type = 'R'
AND c2.constraint_type IN ('P', 'U')
AND c2.owner = 'mySchema'
AND c2.table_name = 'myTable'
AND c1.r_owner = c2.owner
AND c1.r_constraint_Name = c2.constraint_name
order by 1;
Thanks for sharing! can you insert a google translator??
AntwortenLöschenReccomend:
https://quasartechsciencie.blogspot.com/2017/06/sublime-text-potente-editor-de-codigo.html