Wanted:PL/SQL to Disable & Enable Constraints

Ask a Question related to Oracle Server, Design and Development.

  1. #1

    Default Wanted:PL/SQL to Disable & Enable Constraints

    I need one or two PL/SQL's that will let me

    - Disable ALL Constraints for one or more tables

    and at a later time

    - Enable ALL Constraints for one or more tables


    Please post any answers to the Newstgroup.


    Thanks - Albert !
    Albert Zweistein Guest

  2. Similar Questions and Discussions

    1. Enable Disable fields onclick
      I have a cfinput field that is disabled when the form first loads (disabled="true") I want to click a button to enable the field. ...
    2. disable/enable
      I have a form to included these file 1. Radio buttons. button1, button2 2. Some text boxes: fname, lname, address, phone, etc. 3. Some submit...
    3. Validators Enable & Disable Issue
      Hi Guys , I have used few validators on few fields in my form, i have a reset button which reset the current contents of those fields. When i do...
    4. enable/disable
      How can do disable and enable for radio box? it worked for all my text box but not for radio box ======= <script language="JavaScript"> function...
    5. NEED HELP W/ ENABLE/DISABLE CHECKBOXES AND TEXTBOXES
      Hi all, Can you please tell me what's wrong with my code??? i do have this database in wich i have to field.One is a "yes/no" field and another...
  3. #2

    Default Re: Wanted:PL/SQL to Disable & Enable Constraints

    Hi Albert Zweistein, thanks for writing this:
    > I need one or two PL/SQL's that will let me
    >
    > - Disable ALL Constraints for one or more tables
    >
    > and at a later time
    >
    > - Enable ALL Constraints for one or more tables
    >
    >
    > Please post any answers to the Newstgroup.
    >
    >
    > Thanks - Albert !
    >
    I use the following when bulk loading data. Of course, I have to be
    ready to fix any constraint violations when constraints are re-enabled.

    -- ================================================== ==================
    -- Abstract of: prep_bulk_load.sql
    -- When bulk loading tables, we don't want to worry about being
    -- blocked from loading tables in any order we choose by referential
    -- integrity rules. This script is handy in this and other similar
    -- situations.
    --
    -- Generate a script (disable.sql) that will disable all enabled
    -- constraints and triggers for the current schema owner. At the
    -- same time, generate a script (enable.sql) that will enable all
    -- constraints and triggers disabled by disable.sql.
    --
    -- In summary, your steps should be as follows:
    --
    -- 1. Connect to sqlplus as the desired schema owner
    -- 2. Run this script to generate disable.sql and enable.sql
    -- 3. Run disable.sql to disable constraints and triggers
    -- 4. Do whatever tasks are required
    -- 5. run enable.sql to enable constraints and triggers
    -- ================================================== ==================
    set pagesize 0 echo off feedback off trimspool on

    spool disable.sql
    select 'ALTER TABLE ' || lower(table_name) || chr(10) ||
    'DISABLE CONSTRAINT ' || lower(constraint_name) || ';'
    from user_constraints
    where constraint_type = 'R'
    and status = 'ENABLED'
    /
    select 'ALTER TRIGGER ' || lower(trigger_name) || ' DISABLE;'
    from user_triggers
    where status = 'ENABLED'
    /
    spool off

    spool enable.sql
    select 'SPOOL enable.log' from dual;
    select 'ALTER TABLE ' || lower(table_name) || chr(10) ||
    'ENABLE CONSTRAINT ' || lower(constraint_name) || ';'
    from user_constraints
    where constraint_type = 'R'
    and status = 'ENABLED'
    /
    select 'ALTER TRIGGER ' || lower(trigger_name) || ' ENABLE;'
    from user_triggers
    where status = 'ENABLED'
    /
    select 'SPOOL off' from dual;
    spool off

    set pagesize 24 echo on feedback on
    --
    [:%s/Karsten Farrell/Oracle DBA/g]
    Karsten Farrell Guest

  4. #3

    Default Re: Wanted:PL/SQL to Disable & Enable Constraints

    Set up the contraint(s) as "deferrable" and with a simple "alter session"
    command you can defer constraint checking until commit time for all tables .

    --
    "Albert Zweistein" <azwei@web.de> wrote in message
    news:Xns93C0B854DF3A1azweiwebde@62.243.74.162...
    > I need one or two PL/SQL's that will let me
    >
    > - Disable ALL Constraints for one or more tables
    >
    > and at a later time
    >
    > - Enable ALL Constraints for one or more tables
    >
    >
    > Please post any answers to the Newstgroup.
    >
    >
    > Thanks - Albert !


    Burton Peltier Guest

  5. #4

    Default Re: Wanted:PL/SQL to Disable & Enable Constraints

    BEGIN

    DECLARE

    FROM r_disable IN
    (SELECT table_name, constaint_name
    FROM user_constraints
    WHERE constraint_type = 'R'
    AND status = 'ENABLED') LOOP
    execute immediate 'ALTER TABLE ' || r_disable.table_name 'DISABLE
    CONSTRAINT ' || r_disable.constraint_name;
    END LOOP;

    END;

    Cheers

    Greg Johnson
    > --
    > "Albert Zweistein" <azwei@web.de> wrote in message
    > news:Xns93C0B854DF3A1azweiwebde@62.243.74.162...
    > > I need one or two PL/SQL's that will let me
    > >
    > > - Disable ALL Constraints for one or more tables
    > >
    > > and at a later time
    > >
    > > - Enable ALL Constraints for one or more tables
    > >
    > >
    > > Please post any answers to the Newstgroup.
    > >
    > >
    > > Thanks - Albert !
    grjohnson Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139