zoukankan      html  css  js  c++  java
  • 快速删除有外键关联的数据库的数据

    某系统有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

  • 相关阅读:
    c++ 与 c 的区别
    c++ 查看程序运行时间
    串口阻塞与非阻塞
    串口缓冲区
    马拉车算法
    printf 自加自减
    stack
    长度问题
    PCIE的内存地址空间、I/O地址空间和配置地址空间
    数组和指针
  • 原文地址:https://www.cnblogs.com/ego/p/3325184.html
Copyright © 2011-2022 走看看