If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Dropping and recreating a primary key which has already unique index

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-14-04, 15:21
nandra nandra is offline
Registered User
 
Join Date: Sep 2004
Posts: 24
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
Reply With Quote
  #2 (permalink)  
Old 12-14-04, 15:53
bmujeeb bmujeeb is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 12-14-04, 16:19
nandra nandra is offline
Registered User
 
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........
Reply With Quote
  #4 (permalink)  
Old 12-15-04, 06:20
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 1,279
> will be a data loss if we do like this.....

No.
Reply With Quote
  #5 (permalink)  
Old 12-16-04, 10:09
nandra nandra is offline
Registered User
 
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...............
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On