Written by

Technical Consultant at Traverse Health
Question Muhammad Waseem · Jun 29, 2021

Composite primary key

Hi,

How can I define  composite primary key in Cache?

Thanks

Product version: IRIS 2020.1

Comments

Arturo Masero · Jun 29, 2021

Hi,

The 'New Index' wizard allows you to add various properties to the index. Or, manually, you could have something like this:

Index MyIndex On (AProperty, MySecondProperty) [ IdKey ];

0
Arturo Masero  Jun 29, 2021 to Muhammad Waseem

Oh, I was assuming you are using the caché Studio as your IDE. If so, it's under Class > Add > Index...

If you are using VS Code, Eclipse or other, I can't tell you, but the syntax I wrote works fine.

For more reference you have the online documentation, “Index Definitions.”

0
Herman Slagman · Jun 29, 2021

The first question you should ask is: why do I need a composite primary key?
In general, in Cache/IRIS you don't want to mess with the default key provided by %Persistent storage.
In 99% of the cases, a unique index would be sufficient.

0
Dan Pasco  Jul 6, 2021 to Herman Slagman

I agree with Herman - to a point. Leave the IDKEY index alone and just accept the system assigned idkey. In most cases this is the best policy. But - there are potentially several "candidate keys", all can be defined - or not, but one can be chosen to be the "primary key". In that case, define the key not as unique but as "primarykey". Some tooling works better with a defined primary key. It does not interfere with the IDKEY unless it is also defined as the "idkey".

0