- 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 - REMOVE
Sometimes based on our client requirements, we need to add or remove properties to/from existing Nodes or Relationships.
We use Neo4j CQL SET clause to add new properties to existing Nodes or Relationships.
We use Neo4j CQL REMOVE clause to remove existing properties of Nodes or Relationships.
Neo4j CQL REMOVE command is used
- To remove labels of a Node or a Relationship
- To remove properties of a Node or a Relationship
Main Difference between Neo4j CQL DELETE and REMOVE commands -
- DELETE operation is used to delete Nodes and associated Relationships.
- REMOVE operation is used to remove labels and properties.
Similarity between Neo4j CQL DELETE and REMOVE commands -
- Both commands should not be used as alone.
- Both commands should be used with MATCH Command.
Remove Property of a Node/Relationship
We can use same syntax to remove a property or list of properties of a Node or a Relationship permanently from the Database.
REMOVE Property clause syntax
REMOVE <property-name-list>
S.No. | Syntax Element | Description |
---|---|---|
1. | REMOVE | It is a Neo4j CQL keyword. |
2. | <property-name-list> | It is a list of properties to remove it from a Node or a Relationship permanently. |
<property-name-list> syntax
<node-name>.<property1-name>, <node-name>.<property2-name>, .... <node-name>.<propertyn-name>
Syntax Description
S.No. | Syntax Element | Description |
---|---|---|
1. | <node-name> | It is a name of a Node. |
2. | <property-name> | It is a property name of a Node. |
NOTE -
- We should use comma(,) operator to separate the label names list.
- We should use dot(.) operator to separate the node names and label name.
Example
This example demonstrates how to Create a Node and to delete a Property from this Node permanently from the Database.
Step 1 - Open Neo4j Data Browser
Step 2 - Type the below command on Data Browser
CREATE (book:Book {id:122,title:"Neo4j Tutorial",pages:340,price:250})
Step 3 - Click on "Execute" button and observe the results.
It is similar to the below two SQL Commands at a single shot.
CREATE TABLE BOOK( id number, title varchar2(20), pages number, pages number ); INSERT INTO BOOK VALUES (122,'Neo4j Tutorial',340,250);
Here we can observe that one label and one node with 4 properties are created successfully.
Step 4 - Type the below command on Data Browser
MATCH (book : Book) RETURN book
It is similar to the below SQL Command.
SELECT * FROM BOOK;
Step 5 - Click on "Execute" button and observe the results.
Here we can observe that this book node has 4 properties.
Step 6 - Type the below command on Data Browser and click on Execute button to remove "price" property from book node.
MATCH (book { id:122 }) REMOVE book.price RETURN book
It is similar to the below SQL Command.
ALTER TABLE BOOK REMOVE COLUMN PRICE; SELECT * FROM BOOK WHERE ID = 122;
Here we can see only 3 properties of node book because "price" property is deleted.
Sometimes based on client requirements, we need to remove some existing properties to Nodes or Relationships.
We need to use REMOVE clause to remove a property or set of properties.
Example
This example demonstrates how to delete a Property from an existing Node permanently from the Database.
Step 1 - Open Neo4j Data Browser
Step 2 - Type the below command on Data Browser
MATCH (dc:DebitCard) RETURN dc
Step 3 - Click on "Execute" button and observe the results.
Here we can observe that DebitCard node contains 6 properties.
Step 4 - Type the below command on Data Browser
MATCH (dc:DebitCard) REMOVE dc.cvv RETURN dc
Step 5 - Click on "Execute" button and observe the results.
If we observe the output, "cvv" property is removed from "DebitCard" node..
To Remove a Label of a Node/Relationship
We can use same syntax to remove a Label or list of Labels of a Node or a Relationship permanently from the Database.
REMOVE a Label clause syntax:
REMOVE <label-name-list>
S.No. | Syntax Element | Description |
---|---|---|
1. | REMOVE | It is a Neo4j CQL keyword. |
2. | <label-name-list> | It is a list of labels to remove it from a Node or a Relationship permanently. |
<label-name-list> syntax
<node-name>:<label1-name>, <node-name>:<label2-name>, .... <node-name>:<labeln-name>
Syntax Description
S.No. | Syntax Element | Description |
---|---|---|
1. | <node-name> | It is a name of a Node. |
2. | <label-name> | It is a label name of a Node. |
NOTE -
We should use comma(,) operator to separate the label names list.
We should use colon(:) operator to separate the node names and label name.
Example
This example demonstrates how to remove an unwanted label to a Node permanently from the Database.
Step 1 - Open Neo4j Data Browser
Step 2 - Type the below command on Data Browser
MATCH (m:Movie) RETURN m
Step 3 - Click on "Execute" button and observe the results.
Step 4 - Click on node to see its properties window.
Here we can observe that four labels are available to a single node.
As per our client requirement, we need to remove "Picture" label to this node
Step 5 - Type below command on Browser and click on Execute button.
MATCH (m:Movie) REMOVE m:Picture
Step 6 - Click on "Execute" button and observe the results.
Here we can observe that one label is removed from node permanently from the Database.
Step 7 - Type the below command on Data Browser
MATCH (m:Movie) RETURN m
Step 8 - Click on "Execute" button and observe the results.
Step 9 - Click on node to see its properties window.
Here we can observe that this node has only three labels :Movie,Cinema,Film from Properties Window. That means our previous command has removed Picture label successfully.