diff --git a/modules/ROOT/pages/database-administration/aliases/manage-aliases-composite-databases.adoc b/modules/ROOT/pages/database-administration/aliases/manage-aliases-composite-databases.adoc index e1ca3e7f3..b8901f7e1 100644 --- a/modules/ROOT/pages/database-administration/aliases/manage-aliases-composite-databases.adoc +++ b/modules/ROOT/pages/database-administration/aliases/manage-aliases-composite-databases.adoc @@ -160,6 +160,7 @@ SHOW ALIASES FOR DATABASE YIELD * +-----------------------------------------------------------------------------------------------------------------------------------+ ---- +[[delete-composite-database-alias]] == Delete database aliases in composite databases To delete an alias in a composite database, use the `DROP ALIAS FOR DATABASE` command. diff --git a/modules/ROOT/pages/database-administration/composite-databases/delete-composite-databases.adoc b/modules/ROOT/pages/database-administration/composite-databases/delete-composite-databases.adoc index d1710a640..60b50b553 100644 --- a/modules/ROOT/pages/database-administration/composite-databases/delete-composite-databases.adoc +++ b/modules/ROOT/pages/database-administration/composite-databases/delete-composite-databases.adoc @@ -3,8 +3,17 @@ [[composite-databases-delete]] = Delete composite databases -You can delete composite databases using either the command `DROP COMPOSITE DATABASE name` or the more general one `DROP DATABASE name`. -However, keep in mind that the first command will fail if the target database is not composite, while the second one will not fail because it targets any database. +There are two ways of deleting a composite database with constituent database aliases (local or remote) by either dropping the constituent database aliases first and then deleting the composite database, or deleting the composite database while also dropping the constituent database aliases. + +[[composite-databases-delete-without-aliases]] +== Delete a composite database + +Before deleting a composite database, you must ensure that it is not in use by any database aliases. +If the composite database is in use, you must first drop the aliases that reference it. +For more information, see xref:database-administration/aliases/manage-aliases-composite-databases.adoc#delete-composite-database-alias[Delete database aliases in composite databases]. + +You can delete composite databases using either the command `DROP COMPOSITE DATABASE name` or the more general one `DROP DATABASE name`. +However, keep in mind that the first command targets only composite databases, while the second one targets any database. .Query [source, cypher] @@ -12,3 +21,45 @@ However, keep in mind that the first command will fail if the target database is DROP COMPOSITE DATABASE inventory ---- +[role=label--new-5.24] +[[composite-databases-delete-with-aliases]] +== Delete a composite database while dropping its constituents + +You can use the `CASCADE ALIASES` option of the `DROP COMPOSITE DATABASE` Cypher command to drop the constituent database aliases while deleting the composite database. + +[NOTE] +==== +This operation does not deletes the actual target databases of the constituent database aliases. +==== + +The `CASCADE ALIASES` option is useful when you want to delete a composite database and its constituent database aliases in one step. +Using `CASCADE ALIASES` requires the `DROP ALIAS` privilege. +For more information about this privilege, see xref:authentication-authorization/dbms-administration.adoc#access-control-dbms-administration-alias-management[ALIAS MANAGEMENT privileges]. + +.Drop a composite database and its consitutent alias +==== +This example shows how to create a composite database `movies` and a database alias `movies.sweden` for the database `swedish-movies` and then delete the alias `sweden` and the composite database `movies`. + +.Create a composite database `movies` and a database alias `movies.sweden` for the database `swedish-movies` +[source, cypher] +---- +CREATE COMPOSITE DATABASE movies +CREATE ALIAS movies.sweden FOR DATABASE `swedish-movies` +---- + +.Delete the composite database `movies` while also dropping the alias `movies.sweden` +[source, cypher] +---- +DROP COMPOSITE DATABASE movies CASCADE ALIASES +---- +==== + +This behavior is the same for the more general command `DROP DATABASE name` when using it to drop a composite database. + +//The option `RESTRICT` explicitly requests the default behavior of the command. + +[NOTE] +==== +For composite databases, the aliases that are dropped when using the `CASCADE ALIASES` option can be found in the `constituents` column of `SHOW DATABASE`. +==== + diff --git a/modules/ROOT/pages/database-administration/standard-databases/delete-databases.adoc b/modules/ROOT/pages/database-administration/standard-databases/delete-databases.adoc index 47667ff2f..71cbe26b5 100644 --- a/modules/ROOT/pages/database-administration/standard-databases/delete-databases.adoc +++ b/modules/ROOT/pages/database-administration/standard-databases/delete-databases.adoc @@ -17,7 +17,7 @@ Note that all database aliases must be dropped before dropping a database. | [source, syntax, role="noheader"] ---- -DROP [COMPOSITE] DATABASE name [IF EXISTS] [{DUMP\|DESTROY} [DATA]] [WAIT [n [SEC[OND[S]]]]\|NOWAIT] +DROP [COMPOSITE] DATABASE name [IF EXISTS] [RESTRICT \| CASCADE ALIAS[ES]] [{DUMP\|DESTROY} [DATA]] [WAIT [n [SEC[OND[S]]]]\|NOWAIT] ---- |=== @@ -92,9 +92,9 @@ In Neo4j, dumps can be stored in the directory specified by the xref:configurati The option `DESTROY DATA` explicitly requests the default behavior of the command. [[delete-existing-db-with-dump]] -=== Delete a database with `IF{nbsp}EXISTS` and `DUMP DATA`/ `DESTROY DATA` +=== Delete a database with `IF{nbsp}EXISTS` and `DUMP DATA`/`DESTROY DATA` -The options `IF EXISTS` and `DUMP DATA`/ `DESTROY DATA` can also be combined. +The options `IF EXISTS` and `DUMP DATA`/`DESTROY DATA` can also be combined. An example could look like this: @@ -103,4 +103,54 @@ An example could look like this: DROP DATABASE customers IF EXISTS DUMP DATA ---- +[[delete-databases-with-aliases]] +=== 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 xref:authentication-authorization/dbms-administration.adoc#access-control-dbms-administration-alias-management[ALIAS MANAGEMENT privileges]. + +.Drop a database and the local database alias targeting it +==== +The following example creates a database `movies` and a local database alias `films` targeting it: + +[source, cypher] +---- +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: + +[source, cypher] +---- +DROP DATABASE movies CASCADE ALIASES +---- +==== + +The option `RESTRICT` explicitly requests the default behavior of the command. + +[NOTE] +==== +For standard databases, the aliases that are dropped when using the `CASCADE ALIASES` option can be found in the `aliases` column of `SHOW DATABASE`. +==== + +[[delete-existing-databases-with-aliases]] +=== Delete a database with `RESTRICT`/`CASCADE ALIASES` and other command parts + +The options `RESTRICT`/`CASCADE ALIASES` can also be combined with `IF EXISTS` and `DUMP DATA`/`DESTROY DATA`. +For example: + +[source, cypher] +---- +DROP DATABASE movies IF EXISTS CASCADE ALIASES DUMP DATA +---- diff --git a/modules/ROOT/pages/database-administration/syntax.adoc b/modules/ROOT/pages/database-administration/syntax.adoc index e6c3ac7e9..ad6054aa0 100644 --- a/modules/ROOT/pages/database-administration/syntax.adoc +++ b/modules/ROOT/pages/database-administration/syntax.adoc @@ -176,7 +176,7 @@ START DATABASE name [WAIT [n [SEC[OND[S]]]]\|NOWAIT] | [source, syntax, role="noheader"] ---- -DROP [COMPOSITE] DATABASE name [IF EXISTS] [{DUMP\|DESTROY} [DATA]] [WAIT [n [SEC[OND[S]]]]\|NOWAIT] +DROP [COMPOSITE] DATABASE name [IF EXISTS] [RESTRICT \| CASCADE ALIAS[ES]] [{DUMP\|DESTROY} [DATA]] [WAIT [n [SEC[OND[S]]]]\|NOWAIT] ---- |===