Reputation: 110203
I'm a bit unclear on the terminology when creating an index or constraint. For example:
CREATE CONSTRAINT cs ON (p:Person) ASSERT p.name IS UNIQUE
CREATE INDEX my_index FOR (p:Person) ON (p.age)
When is FOR
used and when is ON
used? Or are they two different versions, or is one deprecated? I've also seen ASSERT
vs. REQUIRE
used and also not sure when to use which.
Upvotes: 1
Views: 126
Reputation: 135
The syntax CREATE CONTRAINT [constraint_name] ON ... ASSERT ...
appears to be old. It is not referred to specifically in the current documentation (v4.4). However, it is referred to on the same page as deprecated for the DROP CONSTRAINT
command.
The current syntax is consistently CREATE CONTRAINT [constraint_name] FOR ... REQUIRE ...
Upvotes: 3
Reputation: 5385
If you use CREATE INDEX, it does not enforce unicity. So basically to speed up searches. CREATE CONSTRAINT does enforce unicity.
When you do :schema
, you will see that in both cases, an index is created, because also to enforce unicity, quick lookup helps al lot :)
Upvotes: 0