This section describes 3 types of identity constraints supported by XSD: 'unique', 'key' and 'keyref' identity constraints. They are very similar to concepts of UNIQUE, PRIMARY KEY and FOREIGN KEY constraints on multiple columns in a database table.
XSD offers 3 types of identity constraints:
1. "unique" Identity Constraint - A repeating set of attributes or elements are
specified as a unique identity. Their values must be unique, if exist.
"unique" identity constraint is very similar to the concept of
UNIQUE constraint on multiple columns in a database table.
2. "key" Identity Constraint - A repeating set of attributes or elements are
specified as a key identity. Their values must exist and be unique.
"key" identity constraint is very similar to the concept of
PRIMARY KEY constraint on multiple columns in a database table.
3. "keyref" Identity Constraint - A repeating set of attributes or elements are
specified as a key reference identity. Their values must exist and refer
to existing values another key identity.
"keyref" identity constraint is very similar to the concept of
FOREIGN KEY constraint on multiple columns in a database table.
A good example of a "unique" identity constraint is the "id" attribute used
in XHTML documents. It should have unique values within the document, if used.