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

  • 相关阅读:
    viewpaper
    mfc ui 3 swf
    mfc ui3
    mfc ui2
    mfc ui库
    将Cocos2dX渲染到MFC窗口上
    MFC 框架技术简单研讨
    不可忽略的数据库缓存重建
    google bookmarket api
    android 加载大图片
  • 原文地址:https://www.cnblogs.com/ego/p/3325184.html
Copyright © 2011-2022 走看看