Updating and Deleting Graph Data
Learn to modify existing nodes and relationships using SET and REMOVE, and safely delete data with DELETE and DETACH DELETE.
Modifying Your Graph Data
In this lesson, you'll learn how to update and delete existing nodes and relationships in your Neo4j graph using Cypher. Modifying data is crucial for keeping your graph accurate and up-to-date.
We'll cover the essential clauses: SET for changing properties, REMOVE for taking properties or labels away, and DELETE / DETACH DELETE for removing graph elements entirely.
Update Node Properties with SET
The SET clause is used to modify existing properties on nodes or relationships, or to add new ones. Let's start by updating a node's property.
This example first creates a 'Person' node, then updates their age.
CREATE (p:Person {name: 'Alice', age: 30})
RETURN p
MATCH (p:Person {name: 'Alice'})
SET p.age = 31
RETURN p.name, p.ageAll lessons in this course
- Filtering and Ordering Results
- Aggregation and Projections
- Updating and Deleting Graph Data
- Combining Queries with WITH and UNION