Oracle SQL Developer - 从架构中禁用所有约束

威尔伯索斯

我有两个禁用所有约束的查询,但它们似乎不起作用。

第一个禁用外键:

select 'alter table '||table_name||' disable constraint '||constraint_name||';'
from user_constraints
where constraint_type ='R'
and status = 'ENABLED';

第二个禁用其他所有内容:

select 'alter table '||table_name||' disable constraint '||constraint_name||';'
from user_constraints
where status = 'ENABLED';

现在,当我检查约束时,SELECT * FROM USER_CONSTRAINTS我可以看到它们仍然是“已启用”。为什么是这样?我在运行查询后尝试提交但无济于事。

我的目标是使用这些查询禁用所有表的约束。

托尼·安德鲁斯

根据我上面的评论,运行 2 个查询是不够的,然后您需要运行这些已生成的所有更改表语句。但是,您可以使用 PL/SQL 一次性完成所有操作。我已将 2 个查询合并为一个,用于order by首先处理外键 (constraint_type = 'R'):

begin
  for r in
    ( select 'alter table '||table_name||' disable constraint '||constraint_name as statement
      from user_constraints
      where status = 'ENABLED'
      order by case constraint_type when 'R' then 1 else 2 end
    )
  loop
    execute immediate r.statement;
  end loop;
end;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章