<legend id='Qk8B6'><style id='Qk8B6'><dir id='Qk8B6'><q id='Qk8B6'></q></dir></style></legend>
  • <tfoot id='Qk8B6'></tfoot>
  • <small id='Qk8B6'></small><noframes id='Qk8B6'>

      <bdo id='Qk8B6'></bdo><ul id='Qk8B6'></ul>

    1. <i id='Qk8B6'><tr id='Qk8B6'><dt id='Qk8B6'><q id='Qk8B6'><span id='Qk8B6'><b id='Qk8B6'><form id='Qk8B6'><ins id='Qk8B6'></ins><ul id='Qk8B6'></ul><sub id='Qk8B6'></sub></form><legend id='Qk8B6'></legend><bdo id='Qk8B6'><pre id='Qk8B6'><center id='Qk8B6'></center></pre></bdo></b><th id='Qk8B6'></th></span></q></dt></tr></i><div id='Qk8B6'><tfoot id='Qk8B6'></tfoot><dl id='Qk8B6'><fieldset id='Qk8B6'></fieldset></dl></div>

        禁用 Oracle 中的所有表约束

        时间:2023-09-18

        • <bdo id='J1TSv'></bdo><ul id='J1TSv'></ul>

              <small id='J1TSv'></small><noframes id='J1TSv'>

            1. <i id='J1TSv'><tr id='J1TSv'><dt id='J1TSv'><q id='J1TSv'><span id='J1TSv'><b id='J1TSv'><form id='J1TSv'><ins id='J1TSv'></ins><ul id='J1TSv'></ul><sub id='J1TSv'></sub></form><legend id='J1TSv'></legend><bdo id='J1TSv'><pre id='J1TSv'><center id='J1TSv'></center></pre></bdo></b><th id='J1TSv'></th></span></q></dt></tr></i><div id='J1TSv'><tfoot id='J1TSv'></tfoot><dl id='J1TSv'><fieldset id='J1TSv'></fieldset></dl></div>
            2. <legend id='J1TSv'><style id='J1TSv'><dir id='J1TSv'><q id='J1TSv'></q></dir></style></legend>

                  <tbody id='J1TSv'></tbody>
                <tfoot id='J1TSv'></tfoot>

                  本文介绍了禁用 Oracle 中的所有表约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何使用单个命令禁用 Oracle 中的所有表约束?这可以用于单个表、表列表或所有表.

                  How can I disable all table constrains in Oracle with a single command? This can be either for a single table, a list of tables, or for all tables.

                  推荐答案

                  最好避免写出临时假脱机文件.使用 PL/SQL 块.您可以从 SQL*Plus 运行它或将它放入包或过程中.加入 USER_TABLES 是为了避免视图约束.

                  It is better to avoid writing out temporary spool files. Use a PL/SQL block. You can run this from SQL*Plus or put this thing into a package or procedure. The join to USER_TABLES is there to avoid view constraints.

                  您不太可能真的想禁用所有约束(包括 NOT NULL、主键等).您应该考虑将constraint_type 放在WHERE 子句中.

                  It's unlikely that you really want to disable all constraints (including NOT NULL, primary keys, etc). You should think about putting constraint_type in the WHERE clause.

                  BEGIN
                    FOR c IN
                    (SELECT c.owner, c.table_name, c.constraint_name
                     FROM user_constraints c, user_tables t
                     WHERE c.table_name = t.table_name
                     AND c.status = 'ENABLED'
                     AND NOT (t.iot_type IS NOT NULL AND c.constraint_type = 'P')
                     ORDER BY c.constraint_type DESC)
                    LOOP
                      dbms_utility.exec_ddl_statement('alter table "' || c.owner || '"."' || c.table_name || '" disable constraint ' || c.constraint_name);
                    END LOOP;
                  END;
                  /
                  

                  再次启用约束有点棘手 - 您需要先启用主键约束,然后才能在外键约束中引用它们.这可以通过在constraint_type 上使用ORDER BY 来完成.'P' = 主键,'R' = 外键.

                  Enabling the constraints again is a bit tricker - you need to enable primary key constraints before you can reference them in a foreign key constraint. This can be done using an ORDER BY on constraint_type. 'P' = primary key, 'R' = foreign key.

                  BEGIN
                    FOR c IN
                    (SELECT c.owner, c.table_name, c.constraint_name
                     FROM user_constraints c, user_tables t
                     WHERE c.table_name = t.table_name
                     AND c.status = 'DISABLED'
                     ORDER BY c.constraint_type)
                    LOOP
                      dbms_utility.exec_ddl_statement('alter table "' || c.owner || '"."' || c.table_name || '" enable constraint ' || c.constraint_name);
                    END LOOP;
                  END;
                  /
                  

                  这篇关于禁用 Oracle 中的所有表约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:数据库设计中真的需要外键吗? 下一篇:Oracle PL/SQL - 如何创建一个简单的数组变量?

                  相关文章

                  • <bdo id='JmhPT'></bdo><ul id='JmhPT'></ul>
                • <small id='JmhPT'></small><noframes id='JmhPT'>

                  <i id='JmhPT'><tr id='JmhPT'><dt id='JmhPT'><q id='JmhPT'><span id='JmhPT'><b id='JmhPT'><form id='JmhPT'><ins id='JmhPT'></ins><ul id='JmhPT'></ul><sub id='JmhPT'></sub></form><legend id='JmhPT'></legend><bdo id='JmhPT'><pre id='JmhPT'><center id='JmhPT'></center></pre></bdo></b><th id='JmhPT'></th></span></q></dt></tr></i><div id='JmhPT'><tfoot id='JmhPT'></tfoot><dl id='JmhPT'><fieldset id='JmhPT'></fieldset></dl></div>

                  <legend id='JmhPT'><style id='JmhPT'><dir id='JmhPT'><q id='JmhPT'></q></dir></style></legend>
                    <tfoot id='JmhPT'></tfoot>