-
Notifications
You must be signed in to change notification settings - Fork 0
/
appendix-cypher2.qmd
59 lines (43 loc) · 1.38 KB
/
appendix-cypher2.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
---
title: "O: Deleting Nodes and Relationships"
---
<br>
Deleting nodes and relationships, using the `DELETE` clause in Cypher, is an important operation in managing the graph database.
## Deleting Nodes
The general syntax for deleting a node is:
```cypher
MATCH (n:NodeLabel {propertyName: propertyValue})
DELETE n
```
Where:
- `n` is the node variable
- `NodeLabel` is the label assigned to the node
- `propertyName` is the property name
- `propertyValue` is the value assigned to the property
- `DELETE` is used to delete the node
- `MATCH` is used to find the node to delete
- `...` represents additional properties
### Example: Deleting a Student Node
```cypher
MATCH (s:Student {studentID: '123456'})
DELETE s
```
## Deleting Relationships
The general syntax for deleting a relationship is:
```cypher
MATCH (n1:NodeLabel1)-[r:RELATIONSHIP_TYPE]->(n2:NodeLabel2)
DELETE r
```
Where:
- `n1` and `n2` are the node variables
- `NodeLabel1` and `NodeLabel2` are the labels assigned to the nodes
- `r` is the relationship variable
- `RELATIONSHIP_TYPE` is the type of relationship
- `DELETE` is used to delete the relationship
- `MATCH` is used to find the relationship to delete
- `...` represents additional properties
### Example: Deleting a Relationship Between a Student and an Activity
```cypher
MATCH (s:Student {studentID: '123456'})-[r:ATTENDS]->(a:Activity {activityID: '789'})
DELETE r
```