Keb*_*ber 3 oracle plsql oracle11g dbms-redefinition
我正在使用Oracle11g,并尝试使用dbms_redefinition重新定义表.它工作正常,但在尝试删除临时表时会抛出ORA-02449: unique/primary keys in table referenced by foreign keys错误.
我在SO中找到了一个查找引用的查询,
select table_name, constraint_name, status, owner
from all_constraints
where r_owner = 'MYSCHEMA'
and constraint_type = 'R'
and r_constraint_name in
(
select constraint_name from all_constraints
where constraint_type in ('P', 'U')
and table_name = 'INTERIM_TABLE'
and owner = 'MYSCHEMA'
)
order by table_name, constraint_name
Run Code Online (Sandbox Code Playgroud)
这使
table_name |constraint_name |status |owner
---------------------------------------------------------
anotherTable|TMP$$_anotherTable_JOB_ID0|DISABLED|MYSCHEMA
Run Code Online (Sandbox Code Playgroud)
我想这个约束是在重新定义过程中创建的,没关系,但我也期望它必须被同一个进程删除.这是错的吗?我说,这个约束没有被删除是正常行为的一部分吗?
只需删除约束就可以了
alter table anotherTable
drop constraint TMP$$_anotherTable_JOB_ID0
Run Code Online (Sandbox Code Playgroud)
没有数据丢失?
提前致谢.
- 编辑 - 在考虑了这个之后,我决定删除约束以让临时表被删除.
我已经修改了查询,以便几乎自动地删除指向我想要删除的表的其他表的约束.
DECLARE
my_table varchar2(100);
my_constraint varchar2(100);
BEGIN
select table_name , constraint_name into my_table,my_constraint
from all_constraints
where r_owner = 'MYSCHEMA'
and constraint_type = 'R'
and r_constraint_name in
(
select constraint_name from all_constraints
where constraint_type in ('P', 'U')
and table_name = 'INTERIM_TABLE'
and owner = 'MYSCHEMA'
)
order by table_name, constraint_name;
execute immediate 'ALTER TABLE '||my_table||' DROP CONSTRAINT '|| my_constraint;
END;
/
DROP TABLE MYSCHEMA.INTERIM_TABLE;
Run Code Online (Sandbox Code Playgroud)
这对我有用,但我必须注意,在我的情况下,查询只抛出一行(只有一个依赖表),所以必须修改这个以通过循环或其他方法删除许多约束,如果你认识某人.
如果有人能够找出并解释为什么过程本身不会删除该约束(或者这是正常行为),那将是一件好事.
| 归档时间: |
|
| 查看次数: |
3187 次 |
| 最近记录: |