Deleting Relationships Safely
Introduction
Welcome back to Understanding Graph Databases with Neo4j! You've now completed two units on modifying node properties, and you're making excellent progress in this course. In the previous lessons, you learned how to update and remove properties from nodes using the SET and REMOVE clauses.
Now we're shifting our focus from nodes to relationships. While properties describe individual nodes, relationships are what make graph databases truly powerful by connecting data in meaningful ways. Just as nodes require maintenance, relationships also need to be managed. Sometimes friendships end, collaborations are completed, or connections become outdated. In this lesson, we'll explore how to safely remove relationships from your graph while keeping the connected nodes intact.
The Nature of Relationships in Graphs
Relationships are the connective tissue of graph databases. They represent how entities interact, relate, or associate with each other. A user might be friends with another user, an actor might appear in a movie, or a customer might purchase a product. These connections are just as important as the nodes themselves.
Unlike relational databases, where connections exist implicitly through foreign keys, graph databases store relationships as first-class entities. This means relationships can be created, modified, and deleted independently of the nodes they connect. When you delete a relationship, the nodes on either end remain untouched; only the connection between them disappears. This is a crucial concept: removing a relationship doesn't affect the existence of the nodes themselves.
The DELETE Clause for Relationships
Neo4j uses the DELETE clause to remove both relationships and nodes from the graph. While DELETE can remove nodes as well (which we'll explore in a later lesson), in this lesson we're focusing on using it to eliminate relationships while preserving the nodes they connect. The process always starts with a MATCH clause to identify which relationship you want to delete, followed by DELETE to remove it.
The syntax is straightforward: you match a relationship pattern, assign a variable to the relationship itself (typically using square brackets with a variable name), and then delete that variable. This precision ensures you only remove what you intend to, without accidentally affecting nodes or other relationships in your graph.

