Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Interchanging primary key fields

Former Member
0 Likes
450

Hi,

Can we interchange primary key fields?

Example: I have a table in which the the primay keys are Mandt, Kunnr, Country_code,Vbeln, Posnr.

And this table is in production.

Now can i interchange the order of primary key fields to Mandt,Vbeln, Posnr,Kunnr,Country_code and then transport to production?

Will there be any problem by doing this?

Should i perform Runstats after this?

Regards,

Robin.

1 ACCEPTED SOLUTION
Read only

ThomasZloch
Active Contributor
0 Likes
425

The number and names of the primary key fields remain the same, so there should not be a problem with duplicate keys or losing data. There might be a problem with programs expecting the current sequence of fields, which might have serious performance problems once you change the order of the primary key fields. You should check that in advance.

Make sure you test this in a sandbox or test system with lots of data, compare table contents before and after.

Thomas

2 REPLIES 2
Read only

Former Member
0 Likes
425

interchange primary key fields means that two steps will be executed:

1) drop old index

2) create new index

So the same precautions have to be taken as when simply creating a new index.

There may be a table lock, and this may last for an hour or longer in case it is a huge table.

Have a look at SAP Note 334224 - Important notes for creating indexes.

And for a primary key (or any kind of unique index) you might face the (not very likely) problem that you have got duplicate keys during the short time when there was no primary key. Be prepared!

Whether or not you have to update statistics afterwards will depend on your database. You didn't tell us.

hope this helps

Read only

ThomasZloch
Active Contributor
0 Likes
426

The number and names of the primary key fields remain the same, so there should not be a problem with duplicate keys or losing data. There might be a problem with programs expecting the current sequence of fields, which might have serious performance problems once you change the order of the primary key fields. You should check that in advance.

Make sure you test this in a sandbox or test system with lots of data, compare table contents before and after.

Thomas