HOW ALTER PRIMARY KEY
Hi everyone,
How do you alter primary key on a table that has data?
Any example much appreciated.
Cheers,
Tom
Product version: IRIS 2021.2
Discussion (1)0
Comments
If the data already exists, then this is a non-trivial task, especially if inheritance or Parent/Child is present, since this will lead to a change in the storage scheme of your data.
The easiest way to do this is through an intermediate (temporary) table:- create a new class with the same structure, but with a new primary key;
- move data from the old class into it using SQL (not the merge command);
- delete data/indexes in the old class, then change the primary key in it;
- move data from the new class to the old class, using the merge command;
- delete the new class with the data;
- rebuild the indexes if there are any.
Useful links: MERGEPersistent Objects and InterSystems IRIS SQLIntroduction to Persistent Objects
If you feel insecure with Caché/IRIS, it is better to ask WRC for help.