Keys
A key is a field or combination of fields that uniquely identifies occurrences of entities.
Keys provide a mechanism for record identification, for maintaining relationships between entities, and for improving data retrieval. Uniface can automatically handle all processing related to referential integrity, locking, and foreign key transport using the modeled keys.
Keys are defined as development objects that belong to a modeled entity. Uniface enables you to create the following types of key:
- Primary key—uniquely identifies an occurrence and can consist of one or more fields. An entity can have only one primary key. Uniface always validates primary keys and does not allow them to be edited.
- Candidate keys—also uniquely identify an
occurrence and can consist of one or more fields. These may be a unique combination of fields other
than the primary key. Candidate keys can enforce a unique property for a field or collection of
fields. By default, Uniface validates candidate fields, but this can be changed in the definition.
Entities can have more than one candidate key, because there is often more than one unique field in an entity. Although you can use a candidate key as the foreign key when defining a relationship, it is recommended that you use the primary key.
- Index keys—identifies a field or fields used to
index occurrences. An index is a separate file, internally managed by Uniface, containing all the
values of one or more fields in an entity, sorted in an alphabetical or numeric order. Indexes
improve performance when searching for the required data in a database. You can make Uniface manage
indexes on any field, or collection of fields, by defining the fields concerned as index keys in
the application model. Uniface does not apply specific validation checks to indexes.
Generally, all keys are indexed, but you can also define an index key for any other field or collection of fields in your application model. It is good practice to create an index for fields in the database that you might be using on a regular basis. For example in an application where you might search for a customer name on a regular basis, it is a good idea to create an index for the name field.