Skip to content

Commit 1e8f74d

Browse files
Clarify that CREATE OR REPLACE DB deletes indexes and constraints as well (#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 32fcee5 commit 1e8f74d

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

+15
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,21 @@ CREATE OR REPLACE DATABASE customers
206206

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

209+
Keep in mind that using `CREATE OR REPLACE DATABASE` also removes indexes and constraints.
210+
To preserve them, run the following Cypher commands before the `CREATE OR REPLACE DATABASE` and save their outputs:
211+
212+
[source, cypher]
213+
----
214+
SHOW CONSTRAINTS YIELD createStatement AS statement
215+
----
216+
217+
[source, cypher]
218+
----
219+
SHOW INDEXES YIELD createStatement, owningConstraint
220+
WHERE owningConstraint IS NULL
221+
RETURN createStatement AS statement
222+
----
223+
209224
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).
210225

211226
[NOTE]

0 commit comments

Comments
 (0)