@unique
|
This documentation is not current - it is for TypeDB 2.x, which is no longer supported. View the documentation for TypeDB 3.x: |
The @unique keyword is an annotation, that can be used with an
owns statement to specify, that the selected attribute type must be uniquely owned by data instances of a given type.
Syntax
The syntax of a @unique statement includes:
-
the
@uniquekeyword
<type> owns <attribute-type> @unique;
Behavior
TypeQL statements with the @unique keyword can be used only in Define queries.
The @unique keyword adds a uniqueness constraint for all attributes of the attribute type
owned by data instances of the subject type.
A uniqueness constraint means that every attribute of an attribute type can be owned by no more than one data instance of the subject type. That makes every owned attribute unique among all data instances of the subject 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 @unique annotation, use:
define
object sub entity, owns object-type @unique;