Delete databases
Databases can be deleted by using the command DROP DATABASE
.
Note that all database aliases must be dropped before dropping a database.
Syntax
Command | Syntax |
---|---|
|
|
Examples
Delete a database
To delete the database customers
, run the following command:
DROP DATABASE customers
Both standard databases and composite databases can be deleted using this command. |
The DROP DATABASE
command removes a database entirely.
Therefore, it no longer shows up in the listing provided by the command SHOW DATABASES
:
SHOW DATABASES YIELD name
+---------------------+ | name | +---------------------+ | "movies" | | "neo4j" | | "system" | +---------------------+
Delete a database with IF EXISTS
The DROP DATABASE
command is optionally idempotent, with the default behavior to fail with an error if the database does not exist.
Appending IF EXISTS
to the command ensures that no error is returned and nothing happens if the database does not exist.
It always returns an error if there is an existing alias that targets the database. In that case, the alias needs to be dropped before dropping the database.
DROP DATABASE customers IF EXISTS
Delete a database with DUMP DATA
or DESTROY DATA
By appending DUMP DATA
to the command DROP DATABASE
, you can create a dump of the store files before deleting the database:
DROP DATABASE movies DUMP DATA
These dumps are equivalent to those produced by neo4j-admin database dump
and can be similarly restored using the neo4j-admin database load
command.
In Neo4j, dumps can be stored in the directory specified by the server.directories.dumps.root
setting (by default, the path for storing dumps is <neo4j-home>/data/dumps
).
The option DESTROY DATA
explicitly requests the default behavior of the command.