Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Neo4j Delete Node

  • Last Updated : 23 Aug, 2019

In Neo4j to delete a node or relations between nodes you have to use DELETE clause. To delete any node you need DELETE clause with the MATCH statement, the MATCH statement data will find the specific node and whichever node is matched with the statement that node will be vanished. Similar to the CREATE and RETURN statement just it will replace the CREATE with MATCH and RETURN with the DELETE. Below examples will illustrate the approach.

Example: The basic way to delete a node is to find the node and delete the match node, but before you can check the node is that the node you want to delete by using RETURN statement after that you can fire below query. This query will delete the node where label is “GeeksforGeeks” Tag is “A Computer Science Portal” and the type is “Edutech”.

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

 

  • To delete node:
    $ MATCH (a:GeksforGeeks { Tag : "A Computer Science Portal", Type : "Edutech" }) 
    DELETE a

    Output:

    Deleting multiple nodes:
    To delete multiple nodes use the DELETE statement and separate the nodes by “, ” coma or you can use multiple time MATCH statement Like the below query.



  • Multiple nodes deleted:
    $ DELETE (a:GeeksforGeeks { Tag: "A Computer Science Portal"}), 
    (b:W3School { Tag: "We are the Learner"}) 
    MATCH a, b

    or

    $ MATCH (a:GeeksforGeeks { Tag: "A Computer Science Portal"}) 
    MATCH (b:W3School { Tag: "We are the Learner"}) 
    DELETE a, b
    

    Output:

    Delete all nodes: To delete all the nodes at once is to much short query to fire the below query will delete all the nodes at once.

  • Delete all nodes:
    $ MATCH (n) DELETE n

    Output:

    Note: To delete any node or nodes that containing relationship with other nodes will display an error message.

    My Personal Notes arrow_drop_up
  • Recommended Articles
    Page :