Neo4j CQL - DELETE




Neo4j CQL DELETE clause

Neo4j CQL DELETE clause is used

  • To delete a Node

  • To delete a Node and associated Nodes and Relationships

We are to going to discuss how to delete a node in this chapter. We will discuss how to delete a Node and associated Nodes and Relationships in next chapter.

To Delete a Node:-

We can also delete a Node and all its associated nodes and Relationships at a time permanently from the Database.

DELETE a Node and Relationship clause syntax

DELETE <node1-name>,<node2-name>,<relationship-name>
S.No. Syntax Element Description
1. DELETE It is a Neo4j CQL keyword.
2. <node1-name> It is one end node name used to create a relationship <relationship-name>.
3. <node2-name> It is another node name used to create a relationship <relationship-name>.
4. <relationship-name> It is a relationship name, which is created between <node1-name> and <node2-name>.

NOTE:-

  • We should use comma(,) operator to separate the node names and relationship name.

Example1:-

TThis example demonstrates how to delete a Node and its associate Node and relationship permanently from the Database.

Steps to follow:

  • Open Neo4j Data Browser

  • Neo4j CQL Tutorial

    It is Neo4j Data Browser Homepage

  • Type the below command on Data Browser

MATCH (cc:CreditCard)-[r]-(c:Customer)RETURN r 
Neo4j CQL Tutorial
  • Click on "Execute" button and observe the results.

  • Neo4j CQL Tutorial

    Here we are observing that one node for Customer, one node for CreditCard and a relationship between them is available.

  • Type the below command on Data Browser

  • MATCH (cc: CreditCard)-[rel]-(c:Customer) 
    DELETE cc,c,rel
    
    Neo4j CQL Tutorial
  • Click on "Execute" button and observe the results.

  • Neo4j CQL Tutorial

    Here we can observe that two nodes and their associated 10 relationships are deleted successfully.

    Now check whether the DELETE operation is done successfully or not.

  • Type the below command on Data Browser.

  • MATCH (cc:CreditCard)-[r]-(c:Customer) RETURN r
    
    Neo4j CQL Tutorial
  • Click on "Execute" button and observe the results.

  • Neo4j CQL Tutorial

    Here we can observe that zero rows returned from the database.

    Advertisements