, .
To make it user_idunique and indexed, you should use this:
CREATE CONSTRAINT ON (user:User) ASSERT user.user_id IS UNIQUE
>>> Added 1 constraint, returned 0 rows in 107 ms
To verify that the index has been added correctly:
:SCHEMA
>>> Indexes
>>> ON :User(user_id) ONLINE (for uniqueness constraint)
>>>
>>> Constraints
>>> ON (user:User) ASSERT user.user_id IS UNIQUE
Please note that if you try to delete an index that was automatically created using the uniqueness constraint, it will fail:
DROP INDEX ON :User(user_id)
>>> Unable to drop index on :User(user_id): Index belongs to constraint: :User(user_id)
The correct way to remove this is to remove the uniqueness constraint:
DROP CONSTRAINT ON (user:User) ASSERT user.user_id IS UNIQUE
>>> Removed 1 constraint, returned 0 rows in 108 ms
source
share