Officially out now: The TypeDB 3.0 Roadmap >>

@key

The @key keyword is an annotation, that can be used with an owns statement to specify, that the selected attribute type serves as a key for the subject type.

Syntax

The syntax of a @key statement includes:

Syntax
<type> owns <attribute-type> @key;

Behavior

TypeQL statements with the @key keyword can be used only in Define queries.

The @key keyword adds a unique annotation constraint, as well as a cardinality constraint of exactly one.

The Cardinality constraint of exactly one means, that a data instance of the subject type must have exactly one (no less and no more) attribute of the given attribute type.

Usage in a schema definition

For this example, use a database with the IAM schema and sample data loaded.

Since in Define and Undefine queries you can’t use variables, both subject and object of an owns statement can only be type labels.

For example, to define that the object type owns the object-type attribute type with the @key annotation, use:

Define key query example
define
object owns object-type @key;

Learn more

Learn more about type statement in TypeQL.

Learn about types in TypeQL.