Neo4J Delete Command Lab Day 2

 

Neo4J Commands Lab Day 2


Delete Command:

You can use delete command in for scenarios

  • Delete single node
  • Delete relationships only
  • Delete relationships only
  • Delete all nodes and relationships


To start with Lab, lets quickly create a few nodes and relation ships

Command: 


  • CREATE p = (:Person {name:'Andy'})-[:WORKS_AT]->(:Company {name: 'Neo4j'})<-[:WORKS_AT]-(:Person {name: 'Michael'})
  • RETURN p




Commands and Syntax for Delete


Delete single node

To delete a single node, I created anode and use the DELETE clause:

  • CREATE p = (:Person {name:'Tom Hanks'})
  • MATCH (n:Person {name: 'Tom Hanks'})
  • DELETE n




Delete Relationships Only

It is possible to delete a relationship while leaving the node(s) connected to that relationship otherwise unaffected.


  • CREATE p = (:Person {name: 'Laurence Fishburne'})-[r:ACTED_IN]->(:Person {name: 'Andy Fishburne'})   return p
  • MATCH (n:Person {name: 'Laurence Fishburne'})-[r:ACTED_IN]->()
  • DELETE r


Delete a node with all its relationships

To delete nodes and any relationships connected them, use the DETACH DELETE clause.


  • CREATE p = (:Person {name: 'Laurence Fishburne'})-[r:ACTED_IN]->(:Person {name: 'Andy Fishburne'})   return p
  • MATCH (n:Person {name: 'Carrie-Anne Moss'})
  • DETACH DELETE n


Delete all nodes and relationships

It is possible to delete all nodes and relationships in a graph.



  • MATCH (n)
  • DETACH DELETE n


No comments:
Write comments

Please do not enter spam links

Meet US

Services

More Services