Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2004
    Posts
    24

    Unanswered: Dropping and recreating a primary key which has already unique index

    Hi,
    Iam new to DB2 and i have a table has 2 columns as primary key and i have created a unique index for both the columns.But while altering the table and adding constraint primary key i specified only one column.Now i want to revert it back to alter table add constraint sql12345678 with primary key (column1,column2).

    Ex:

    Create table tabname(col1 integer not null,col2 integer not null,col3 integer not nuill,col4 integer not null)

    create unique index uix_col1 on table tabname (col1,col2);

    alter table tabname add constraint sql123456789 primary key(col1);


    but i want like this,

    Create table tabname(col1 integer not null,col2 integer not null,col3 integer not nuill,col4 integer not null)

    create unique index uix_col1 on table tabname (col1,col2);

    alter table tabname add constraint sql123456789 primary key(col1,col2);

    is there any way .....

    thanks in advance
    nandra

  2. #2
    Join Date
    Mar 2004
    Posts
    448
    You can do that

    alter table <tablename> drop constraint sql123456789

    Now if you check the syscat.indexes , you should have only index on that table.

    Now

    alter table <tablename> add constraint sql1234 primary key(col1,col2)

    It will use the previous index to enforce the primary key constraint.

    Now you have one more index to maintain.

    regards

    Mujeeb

  3. #3
    Join Date
    Sep 2004
    Posts
    24
    Quote Originally Posted by bmujeeb
    You can do that

    alter table <tablename> drop constraint sql123456789

    Now if you check the syscat.indexes , you should have only index on that table.

    Now

    alter table <tablename> add constraint sql1234 primary key(col1,col2)

    It will use the previous index to enforce the primary key constraint.

    Now you have one more index to maintain.

    regards

    Mujeeb

    thanks for the help.............will be a data loss if we do like this........

  4. #4
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    > will be a data loss if we do like this.....

    No.

  5. #5
    Join Date
    Sep 2004
    Posts
    24
    Quote Originally Posted by Wim
    > will be a data loss if we do like this.....

    No.
    Thanks everyone for the help...............

Posting Permissions

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