neo4j
  1. neo4j-delete-clause

Delete Clause - (Neo4j Write Clauses)

The DELETE clause is a write clause in the Neo4j query language used to delete nodes, relationships, and properties from the graph data model.

Syntax

The basic syntax for the DELETE clause is as follows:

MATCH (n)
DELETE n

This query deletes all nodes in the graph.

To delete specific nodes or relationships, use a WHERE clause:

MATCH (n:Label)
WHERE n.property = 'value'
DELETE n

This query deletes all nodes with the Label label and the property property equal to 'value'.

To delete specific relationships, use the MATCH clause:

MATCH (a)-[r:Rel]->(b)
DELETE r

This query deletes all relationships with the Rel type connecting nodes a and b.

Example

Suppose we have a graph with the following nodes and relationships:

(:Person {name: 'Alice'})-[:KNOWS]->(:Person {name: 'Bob'})
(:Person {name: 'Bob'})-[:LIVES_IN]->(:City {name: 'New York'})

To delete the KNOWS relationship between Alice and Bob, we can run the following query:

MATCH (:Person {name: 'Alice'})-[r:KNOWS]->(:Person {name: 'Bob'})
DELETE r

This query will delete the KNOWS relationship between Alice and Bob.

Output

The DELETE clause does not return any output. It simply deletes nodes, relationships, and properties from the graph data model.

Explanation

The DELETE clause is used to delete nodes, relationships, and properties in the Neo4j graph data model. It can be used to delete all nodes in the graph or to delete specific nodes, relationships, and properties.

When deleting specific nodes or relationships, a MATCH clause is used to identify the nodes or relationships to be deleted, and a DELETE clause is used to delete them.

Use

The DELETE clause is used to remove nodes, relationships, and properties from the graph data model. It can be used to clean up data or to modify the graph structure.

It is important to be careful when using the DELETE clause, as it permanently removes data from the graph data model.

Important Points

  • The DELETE clause is used to delete nodes, relationships, and properties from the graph data model.
  • The MATCH clause is used to identify the nodes or relationships to be deleted, and the DELETE clause is used to delete them.
  • The DELETE clause permanently removes data from the graph data model.

Summary

In summary, the DELETE clause is a write clause in the Neo4j query language used to delete nodes, relationships, and properties from the graph data model. It can be used to clean up data or to modify the graph structure. However, it is important to use it carefully, as it permanently removes data from the graph data model.

Published on: