The ID can be based on a specific property of the class, if that property is unique per instance. For example, you could use a drug code as the ID. To define a class this way, add an index like the following to the class:
Index IndexName On PropertyName [ IdKey ];
Or (equivalently):
Index IndexName On PropertyName [ IdKey, Unique ];
Where IndexName is the name of the index, and PropertyName is the name of the property.
If you define a class this way, when InterSystems IRIS saves an object for the first time, it uses the value of that property as the ID. Furthermore, InterSystems IRIS requires a value for the property and enforces uniqueness of that property. If you create another object with the same value for the designated property and then attempt to save the new object, InterSystems IRIS issues this error:
ERROR #5805: ID key not unique for extent
Also, InterSystems IRIS prevents you from changing that property in the future. That is, if you open a saved object, change the property value, and try attempt to save the changed object, InterSystems IRIS issues this error:
ERROR #5814: Oid previously assigned
This message refers to the OID rather than the ID, because the underlying logic prevents the OID from being changed; the OID is based on the ID.
The ID can be based on multiple properties. To define a class this way, add an index like the following to the class:
Index IndexName On (PropertyName1,PropertyName2,...) [ IdKey, Unique ];
Or (equivalently):
Index IndexName On (PropertyName1,PropertyName2,...) [ IdKey ];
Where IndexName is the name of the index, and PropertyName1, PropertyName2, and so on are the property names.
If you define a class this way, when InterSystems IRIS saves an object for the first time, it generates an ID as follows:
PropertyName1||PropertyName2||...
Furthermore, InterSystems IRIS requires values for the properties and enforces uniqueness of the given combination of properties. It also prevents you from changing any of those properties.