Constraints indicate that element values must be unique within their specified scope. Constraints are only available in a model targeted with XSD.
Each constraint has two specific attributes: selector and field.
In a schema, a constraint is declared with its corresponding tag: <unique>, <key> or <keyRef>.
There are three kinds of identity constraints:
A Unique constraint - specifies that an element or an attribute value (or set of values) must be unique or null within a specified scope. For example:
Generated schema:
The UNIQUENUM unique constraint, defined on the project element, specifies that the numEmployee attribute must be unique or null within the employee element
A Key constraint - specifies that an element or an attribute value (or set of values) must be a key within a specified scope; the data must be unique, not null, and always present within a specified scope. For example:
Generated schema:
The KEYCODE key constraint, defined on the project element, specifies that the code attribute must be unique, not null and always present within the product element.
A KeyRef constraint - specifies that an element or attribute value (or set of values) corresponds to the value of a specified key or unique constraint. A keyRef is a reference to a key or a unique constraint. For example:
Generated schema:
The KEYREF_UNIGOLD keyRef, defined on the product element, by reference to the UNIGOLD unique constraint, specifies that the gold attribute must be unique or null within the component_2 element, as well as it must be unique or null within the component_1 element (See UNIGOLD).