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.
Delete a database with IF EXISTS
and DUMP DATA
/DESTROY DATA
The options IF EXISTS
and DUMP DATA
/DESTROY DATA
can also be combined.
An example could look like this:
DROP DATABASE customers IF EXISTS DUMP DATA
Delete a database with local database aliases targeting it
There are two ways of dropping a database that is the target of local database aliases:
-
Drop the local database aliases first, then use
DROP DATABASE name
to drop the database. Remote database aliases targeting the database do not affect the deletion of the database and therefore dos not need to be dropped beforehand. -
Use
DROP DATABASE name CASCADE ALIASES
to also drop the local database aliases targeting it while dropping the database. If any of the dropped database aliases are constituents of composite databases, those composite databases will not be dropped. This command does not affect the remote database aliases targeting the database being dropped. They will simply no longer resolve their targets as if they were created targeting a non-existing database.
Using CASCADE ALIASES
requires the DROP ALIAS
privilege.
For more information about the privilege, see ALIAS MANAGEMENT privileges.
The following example creates a database movies
and a local database alias films
targeting it:
CREATE DATABASE movies
CREATE ALIAS films FOR DATABASE movies
Then, the database movies
and the local database alias films
can be dropped using the following command:
DROP DATABASE movies CASCADE ALIASES
The option RESTRICT
explicitly requests the default behavior of the command.
For standard databases, the aliases that are dropped when using the |