Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions modules/ROOT/pages/clauses/delete.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ For more information, see link:{neo4j-docs-base-uri}/operations-manual/{page-ver
[[delete-all-nodes-and-relationships]]
== Delete all nodes and relationships

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

.Query
.Delete all nodes and relationships
[source, cypher, indent=0]
----
MATCH (n)
Expand All @@ -142,8 +142,25 @@ DETACH DELETE n
Deleted 3 nodes, deleted 1 relationship
----

[TIP]
====
`DETACH DELETE` is not suitable for deleting large amounts of data, but is useful when experimenting with small example datasets.
To delete large amounts of data, instead use xref::subqueries/subqueries-in-transactions.adoc#delete-with-call-in-transactions[CALL subqueries in transactions].
====
`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].

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.

.Delete all nodes and relationships using `CALL` subqueries
[source, cypher]
----
MATCH (n)
CALL (n) {
DETACH DELETE n
} IN TRANSACTIONS
----

To remove all data, including indexes and constraints, recreate the database using the following command: `CREATE OR REPLACE DATABASE name`.

.Delete a database and recreate it
[source, cypher]
----
CREATE OR REPLACE DATABASE neo4j
----

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`].
4 changes: 3 additions & 1 deletion modules/ROOT/pages/queries/basic.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -901,4 +901,6 @@ MATCH (n)
DETACH DELETE n
----

For more information, see the section on the xref:clauses/delete.adoc[] clause.
[NOTE]
`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].
For more information, and alternatives to `DETACH DELETE`, see xref:clauses/delete.adoc#delete-all-nodes-and-relationships[`DELETE` -> Delete all nodes and relationships].
Loading