15.21. Delete

15.21.1. Delete single node
15.21.2. Remove a node and connected relationships
15.21.3. Remove a property

Removing graph elements — nodes, relationships and properties, is done with DELETE.

15.21.1. Delete single node

To remove a node from the graph, you can delete it with the DELETE clause.

Query

START n = node(4)
DELETE n

Nothing is returned from this query, except the count of affected nodes.

Result

Nodes deleted: 1
1 ms

(empty result)


Try this query live. (1) {"age":25,"name":"Tobias"} (2) {"age":34,"name":"Peter"} (3) {"age":36,"name":"Andres"} (3)-[:KNOWS]->(1) {} (3)-[:KNOWS]->(2) {} start n = node(4) delete n

15.21.2. Remove a node and connected relationships

If you are trying to remove a node with relationships on it, you have to remove these as well.

Query

START n = node(3)
MATCH n-[r]-()
DELETE n, r

Nothing is returned from this query, except the count of affected nodes.

Result

Nodes deleted: 1
Relationships deleted: 2
2 ms

(empty result)


Try this query live. (1) {"age":25,"name":"Tobias"} (2) {"age":34,"name":"Peter"} start n = node(3) match n-[r]-() delete n, r

15.21.3. Remove a property

Neo4j doesn’t allow storing null in properties. Instead, if no value exists, the property is just not there. So, to remove a property value on a node or a relationship, is also done with DELETE.

Query

START andres = node(3)
DELETE andres.age
RETURN andres

The node is returned, and no property age exists on it.

Result

andres
1 row
Properties set: 1
2 ms

Node[3]{name:"Andres"}


Try this query live. (1) {"age":25,"name":"Tobias"} (2) {"age":34,"name":"Peter"} (3) {"name":"Andres"} (3)-[:KNOWS]->(1) {} (3)-[:KNOWS]->(2) {} start andres = node(3) delete andres.age return andres