Neo4j CQL - DROP UNIQUE



We have already discussed Creating UNIQUE Constraint operations with examples in previous chapter. Now We will discuss Dropping UNIQUE Constraint operation with examples in this chapter.

Drop UNIQUE Constraint

Neo4j CQL has provided "DROP CONSTRAINT" command to delete existing Unique constraint from a NODE's or Relationship's property.

Drop UNIQUE Constraint syntax:

DROP CONSTRAINT ON (<label_name>)
ASSERT <property_name> IS UNIQUE

Syntax Description

S.No.Syntax ElementDescription
1.DROP CONSTRAINT ONIt is a Neo4j CQL keyword.
2.<label_name>It is the label name of a Node or a Relationship.
3.ASSERTIt is a Neo4j CQL keyword.
4.<property_name>It is the property name of a Node or a Relationship.
5.IS UNIQUEIt is a Neo4j CQL keyword to inform the Neo4j Database server to create a unique constraint.

NOTE -

The above syntax describes that it drops a Unique constraint from <property_name> of <label_name> of a Node or a Relationship.

Example -

This example demonstrates how to Check whether UNIQUE Constraint is created on number property of a CreditCard Node or not.

Step 1 - Type the below command at dollar prompt in Data Browser.

MATCH (cc:CreditCard) 
RETURN cc.id,cc.number,cc.name,cc.expiredate,cc.cvv
Neo4j CQL Tutorial

Step 2 - Click on Execute button and observe the results.

Neo4j CQL Tutorial

We can observe that Database contains 3 CreditCard nodes.

Step 3 - Type the below command at dollar prompt in Data Browser.

CREATE (cc:CreditCard {id:22,number:222222,
      name:'BBB',expiredate:'10/10/2017',cvv:222})
Neo4j CQL Tutorial

Step 4 - Click on Execute button and observe the results.

Neo4j CQL Tutorial

It means one Unique constraint is create on number property of a CreditCard Node

Example -

This example demonstrates how to drop an existing UNIQUE Constraint from number property of a CreditCard Node.

Step 1 - Type the below command at dollar prompt in Data Browser.

MATCH (cc:CreditCard) 
RETURN cc.id,cc.number,cc.name,cc.expiredate,cc.cvv
Neo4j CQL Tutorial

Step 2 - Click on Execute button and observe the results.

Neo4j CQL Tutorial

We can observe that Database contains 3 CreditCard nodes.

Step 3 - Type the below command at dollar prompt in Data Browser.

DROP CONSTRAINT ON (cc:CreditCard)
ASSERT cc.number IS UNIQUE
Neo4j CQL Tutorial

Step 4 - Click on Execute button and observe the results.

Neo4j CQL Tutorial

AS CreditCard.number does not unique constraint, we create as many duplicate nodes as we want.

Step 5 - Then execute the below commands form Data Browser one by one

CREATE (cc:CreditCard 
{id:22,number:222222,name:'BBB',expiredate:'10/10/2017',cvv:222})
CREATE (cc:CreditCard 
{id:22,number:222222,name:'BBB',expiredate:'10/10/2017',cvv:333})
CREATE (cc:CreditCard 
{id:22,number:222222,name:'PPP',expiredate:'12/12/2017',cvv:999})

They create three node with number = 222222. Now we execute the below command form Data Browser to confirm that our Database contains duplicate nodes for CreditCard

MATCH (cc:CreditCard) 
RETURN cc.id,cc.number,cc.name,cc.expiredate,cc.cvv
Neo4j CQL Tutorial
Advertisements