Skip to content

Commit d8782e9

Browse files
clarify detach delete
1 parent e1047a2 commit d8782e9

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

modules/ROOT/pages/clauses/delete.adoc

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,23 +127,47 @@ For more information, see link:{neo4j-docs-base-uri}/operations-manual/{page-ver
127127
[[delete-all-nodes-and-relationships]]
128128
== Delete all nodes and relationships
129129

130-
It is possible to delete all nodes and relationships in a graph.
131130

132-
.Query
131+
It is possible to delete all nodes and relationships in a graph.
132+
133+
134+
.Delete all nodes and relationships
133135
[source, cypher, indent=0]
134136
----
135137
MATCH (n)
136138
DETACH DELETE n
137139
----
138140

141+
139142
.Result
140143
[role="queryresult",options="footer",cols="1*<m"]
141144
----
142145
Deleted 3 nodes, deleted 1 relationship
143146
----
144147

145-
[TIP]
146-
====
147-
`DETACH DELETE` is not suitable for deleting large amounts of data, but is useful when experimenting with small example datasets.
148-
To delete large amounts of data, instead use xref::subqueries/subqueries-in-transactions.adoc#delete-with-call-in-transactions[CALL subqueries in transactions].
149-
====
148+
149+
`DETACH DELETE` is useful when experimenting with small example datasets, but it is not suitable for deleting large amounts of data, nor does it delete xref:indexes/search-performance-indexes/overview.adoc[indexes] and xref:constraints/index.adoc[constraints].
150+
151+
152+
To delete large amounts of data without deleting indexes and constraints, use xref::subqueries/subqueries-in-transactions.adoc#delete-with-call-in-transactions[CALL subqueries in transactions] instead.
153+
154+
155+
.Delete all nodes and relationships using `CALL` subqueries
156+
[source, cypher]
157+
----
158+
MATCH (n)
159+
CALL (n) {
160+
DETACH DELETE n
161+
} IN TRANSACTIONS
162+
----
163+
164+
165+
To delete everything in a database, including indexes and constraints, you can recreate the database using the following command: `CREATE OR REPLACE DATABASE name`.
166+
For more information, see the link:{neo4j-docs-base-uri}/operations-manual/current/database-administration/standard-databases/create-databases/#_create_databases_with_if_not_exists_or_or_replace[Operations Manual -> Create databases with `IF NOT EXISTS` or `OR REPLACE`].
167+
168+
169+
.Delete everything in a database by recreating it
170+
[source, cypher]
171+
----
172+
CREATE OR REPLACE DATABASE neo4j
173+
----

modules/ROOT/pages/queries/basic.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,4 +901,6 @@ MATCH (n)
901901
DETACH DELETE n
902902
----
903903

904-
For more information, see the section on the xref:clauses/delete.adoc[] clause.
904+
[NOTE]
905+
`DEATCH DELETE` is not suitable for deleting large amounts of data, nor does it delete xref:indexes/search-performance-indexes/overview.adoc[indexes] and xref:constraints/index.adoc[constraints].
906+
For more information and alternatives to `DETACH DELETE`, see xref:clauses/delete.adoc#delete-all-nodes-and-relationships[`DELETE` -> Delete all nodes and relationships].

0 commit comments

Comments
 (0)