某系统有600张表,要求删除业务数据,但保留基础数据(部门和人员等)和字典数据。

如果一张表一张表删除工作量就大了,因为外键关联决定了删除必须有先后顺序。

我们可以在删除前禁用外键,待删除完毕之后再启用外键。

当然,最后启用的时候发现删除了不应该删除的数据,因此删除前最好做完整备份。

 

生成禁用外键的脚本:

select 'alter table '|| t.table_name||' disable constraint '||t.constraint_name||';'
from user_constraints t where t.constraint_type = 'R'
order by t.table_name

 

生成启用外键的脚本:

 

select 'alter table '|| t.table_name ||' enable constraint '||t.constraint_name||';'
from user_constraints t where t.constraint_type = 'R'
order by t.table_name

相关文章:

  • 2021-09-30
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
  • 2022-12-23
  • 2021-04-01
  • 2021-10-12
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-25
  • 2021-08-04
  • 2021-09-21
  • 2022-12-23
  • 2021-08-08
  • 2022-12-23
相关资源
相似解决方案