- Neo4j Tutorial
- Neo4j - Home
- Neo4j - Overview
- Neo4j - Data Model
- Neo4j - Environment Setup
- Neo4j - Building Blocks
- Neo4j CQL Write Clauses
- Neo4j - Merge Command
- Neo4j - Set Clause
- Neo4j - Delete Clause
- Neo4j - Remove Clause
- Neo4j - Foreach Clause
- Neo4j CQL Read Clause
- Neo4j - Match Clause
- Neo4j - Optional Match Clause
- Neo4j - Where Clause
- Neo4j - Count Function
- Neo4j CQL General Clauses
- Neo4j - Return Clause
- Neo4j - Order By Clause
- Neo4j - Limit Clause
- Neo4j - Skip Clause
- Neo4j - With Clause
- Neo4j - Unwind Clause
- Neo4j CQL Functions
- Neo4j - String Functions
- Neo4j - Aggregation Function
- Neo4j CQL Admin
- Neo4j - Backup & Restore
- Neo4j - Index
- Neo4j - Create Unique Constraint
- Neo4j - Drop Unique
- Neo4j Useful Resources
- Neo4j - Quick Guide
- Neo4j - Useful Resources
- Neo4j - Discussion
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 Element | Description |
---|---|---|
1. | DROP CONSTRAINT ON | It is a Neo4j CQL keyword. |
2. | <label_name> | It is the label name of a Node or a Relationship. |
3. | ASSERT | It is a Neo4j CQL keyword. |
4. | <property_name> | It is the property name of a Node or a Relationship. |
5. | IS UNIQUE | It 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
Step 2 - Click on Execute button and observe the results.
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})
Step 4 - Click on Execute button and observe the results.
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
Step 2 - Click on Execute button and observe the results.
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
Step 4 - Click on Execute button and observe the results.
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