Skip to content

Commit 1739914

Browse files
Clarify that CREATE OR REPLACE DB deletes indexes and constraints as well (neo4j#2154)
You may need to preserve the database structure (indexes and constraints) when you move the database from test env to production. In this case, it's important to know that the `CREATE OR REPLACE DB` cmd removes not only data but also indexes and constraints. If you want to keep them, you have to do it before executing the command.
1 parent e8b8fc8 commit 1739914

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

modules/ROOT/pages/database-administration/standard-databases/create-databases.adoc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,21 @@ CREATE OR REPLACE DATABASE customers
205205

206206
This is equivalent to running `DROP DATABASE customers IF EXISTS` followed by `CREATE DATABASE customers`.
207207

208+
Keep in mind that using `CREATE OR REPLACE DATABASE` also removes indexes and constraints.
209+
To preserve them, run the following Cypher commands before the `CREATE OR REPLACE DATABASE` and save their outputs:
210+
211+
[source, cypher]
212+
----
213+
SHOW CONSTRAINTS YIELD createStatement AS statement
214+
----
215+
216+
[source, cypher]
217+
----
218+
SHOW INDEXES YIELD createStatement, owningConstraint
219+
WHERE owningConstraint IS NULL
220+
RETURN createStatement AS statement
221+
----
222+
208223
The behavior of `IF NOT EXISTS` and `OR REPLACE` apply to both standard and composite databases (e.g. a composite database may replace a standard database or another composite database).
209224

210225
[NOTE]

0 commit comments

Comments
 (0)