DBAsupport.com Forums - Powered by vBulletin
Results 1 to 7 of 7

Thread: Enabling Primary Key Constraint

  1. #1
    Join Date
    Jun 2001
    Posts
    243

    Question

    I issued this command to disable the primary key and related foreign keys...

    ALTER TABLE table_name
    DISABLE CONSTRAINT constraint_name_pk CASCADE;

    now I want to enable the primary key and all the foreign keys that I disabled....which command do I need to use?

    ALTER TABLE table_name
    ENABLE CONSTRAINT constraint_name_pk;
    (this only enables the primary key, what about the foreign keys?)

    Thanks....=)

  2. #2
    Join Date
    Feb 2001
    Location
    Paris, France
    Posts
    809
    select 'alter table ' || table_name || ' enable constraint ' || constraint_name || ';'
    from user_constraints
    where status = 'DISABLED'

  3. #3
    Join Date
    Jun 2001
    Posts
    243
    I know how to find the status whether it's enabled or disabled...my question was whether you can enable the primary key as well as foreign keys at the same time like I did to disabled it.

  4. #4
    Join Date
    Jul 2001
    Location
    Netherlands (Utrecht)
    Posts
    21
    Why didn't you asked this in the first place...

    Because at your first post Pipo gave you the one and only anwser there is...

    Now you'r asking somthing totaly different..

    No you can't... (That is the anwser at your second question)
    J.Jongman - DBA

  5. #5
    Everyone is getting confused .


    Pipo has NOT provided a method of checking which constraints to enable.

    He has provided a piece of SQL that creates SQL to enable all the constraints that are disabled.

    Just like was asked in the first post and third post.

    Nice one Pipo

  6. #6
    Join Date
    Aug 2000
    Posts
    17
    There is no functionality of this kind.... Enable Cascade does not exist.

    Furthermore you lose all the index storage information...
    so best thing is to create a enable script before disabling the constraints ;-).

    Roger

  7. #7
    Join Date
    Aug 2000
    Posts
    462
    Not only that, but in 8i, if you have an index which uses the proposed PK column first, then that index will be used to enforce the PK, even if it is a non-unique index! When you disable the PK, the PK index which was (probably) created with it is dropped. When you enable that same PK, the index will not be recreated unless no substitute is available. Don't ever disable a PK without first querying the DD to determine what exists at that time. You may lose some vital info that will be a pain to recreate . . .

    Oracle DBA and Developer

Posting Permissions

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


Click Here to Expand Forum to Full Width