These special field names are used to avoid several instances of the same field in a record, and to implement keys in record sets. Their usage is:
%unique: field1 field2 ... fieldN %key: field
The list of field names are separated by one or more blank characters.
The %unique
special field allows to declare fields as unique,
meaning there cannot exist more than one field with the same name in a
single record.
For example, an entry in an addressbook database could contain an
Age
field. It does not make sense for a single person to be of
several ages, so that field could be declared as “unique” in the
corresponding record descriptor as follows:
%rec: Contact %mandatory: Name %unique: Age
Several %unique
fields can appear in the same record
descriptor. The set of unique fields is the union of all the entries.
%key
makes the referred field the primary key of the record
set. Its effect is that any field with that name must be both unique
and mandatory, and additionally the values of those fields shall be
unique in the context of the record set. This closely corresponds to
the notion of “primary key” usually implemented in the relational
systems.
Consider for example a database of items in a stockage. Each item is
idenfitied by a numerical Id
field. No item may have more than
one Id
, and no items may exist without an associated
Id
. Additionally, no two items may share the same Id
.
This common situation can be implementing by declaring Id
as
the key in the record descriptor:
%rec: Item %key: Id %mandatory: Title Id: 1 Title: Box Id: 2 Title: Sticker big
It would not make sense to have several primary keys in a record set,
and thus it is not allowed to have several %key
fields in the
same record descriptor. That situation is considered a data integrity
violation and will be reported by a checking tool.