Share via


identity ("M" Keywords)

[This content is no longer valid. For the latest information on "M", "Quadrant", SQL Server Modeling Services, and the Repository, see the Model Citizen blog.]

The identity constraint specifies the field or fields that make up the identity of an entity, which is a value that is unique within an extent. There can be only one identity constraint on an entity.

The identity constraint can be specified on an entity declaration or on an extent declaration, but not on both. An entity declaration on a derived type supersedes that of any type it derives from.

Fields of type Collection are not supported in identity constraints.

Syntax

identity fieldname

or

identity fieldname1 , fieldname2, … fieldnameN

The identity constraint is specified as one of the clauses in a where constraint. If the identity constraint is the last clause in the where constraint, then it must be terminated with a ;.

Examples

Single Field

The following code is an example of an identity constraint that consists of a single field, an employee's last name. This is obviously not a recommended practice, because a last name could easily occur more than once.

module Example 
{
    type Employee 
    {
        LastName: Text#256;
        FirstName: Text#256;
    }
    Employees : Employee* where identity LastName;
}

Multiple Fields

You can also specify an identity constraint that lists multiple fields. The following code is an example of such a constraint. This example is given for syntax only: using last and first name is not a reliable identifier.

module Example 
{
    type Employee 
    {
        LastName: Text#100;
        FirstName: Text#100;
    }
    Employees : Employee* where identity (LastName, FirstName);
}

See Also

Concepts

where ("M" Keywords)