Existence constraint
Existence constraint enforces that each vertex that has a specific label
also must have the specified property
. Only one label and property can be
supplied at a time. This constraint can be enforced using the following
language construct:
For example, suppose you are keeping track of basic employee info in your database. Obviously, each employee should have a first name and last name. You can enforce this by issuing the following queries:
You can confirm that your constraint was successfully created by issuing the following query:
You should get a result similar to this:
Trying to modify the database in a way that violates the constraint will yield an error.
Constraints can also be dropped using the DROP
keyword. For example,
dropping the previously created constraints can be done by the following
query:
Now, SHOW CONSTRAINT INFO;
yields an empty set.
#
Where to next?To learn more about Memgraph's functionalities, visit the Reference guide. For real-world examples of how to use Memgraph, we strongly suggest going through one of the available Tutorials.