Skip to content

Commit 6276ef5

Browse files
Clarify DETACH DELETE (#1156)
1 parent ce3dd84 commit 6276ef5

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

modules/ROOT/pages/clauses/delete.adoc

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ 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.
130+
It is possible to delete all nodes and relationships in a graph.
131131

132-
.Query
132+
.Delete all nodes and relationships
133133
[source, cypher, indent=0]
134134
----
135135
MATCH (n)
@@ -142,8 +142,25 @@ DETACH DELETE n
142142
Deleted 3 nodes, deleted 1 relationship
143143
----
144144

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-
====
145+
`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].
146+
147+
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.
148+
149+
.Delete all nodes and relationships using `CALL` subqueries
150+
[source, cypher]
151+
----
152+
MATCH (n)
153+
CALL (n) {
154+
DETACH DELETE n
155+
} IN TRANSACTIONS
156+
----
157+
158+
To remove all data, including indexes and constraints, recreate the database using the following command: `CREATE OR REPLACE DATABASE name`.
159+
160+
.Delete a database and recreate it
161+
[source, cypher]
162+
----
163+
CREATE OR REPLACE DATABASE neo4j
164+
----
165+
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`].

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+
`DETACH 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)