ALTER DATABASE

Description

ALTER DATABASE statement changes the properties or location of a database. Please note that the usage of DATABASE, SCHEMA and NAMESPACE are interchangeable and one can be used in place of the others. An error message is issued if the database is not found in the system.

ALTER PROPERTIES

ALTER DATABASE SET DBPROPERTIES statement changes the properties associated with a database. The specified property values override any existing value with the same property name. This command is mostly used to record the metadata for a database and may be used for auditing purposes.

Syntax

  1. ALTER { DATABASE | SCHEMA | NAMESPACE } database_name
  2. SET { DBPROPERTIES | PROPERTIES } ( property_name = property_value [ , ... ] )

Parameters

  • database_name

    Specifies the name of the database to be altered.

ALTER LOCATION

ALTER DATABASE SET LOCATION statement changes the default parent-directory where new tables will be added for a database. Please note that it does not move the contents of the database’s current directory to the newly specified location or change the locations associated with any tables/partitions under the specified database (available since Spark 3.0.0 with the Hive metastore version 3.0.0 and later).

Syntax

  1. ALTER { DATABASE | SCHEMA | NAMESPACE } database_name
  2. SET LOCATION 'new_location'

Parameters

  • database_name

    Specifies the name of the database to be altered.

Examples

  1. -- Creates a database named `inventory`.
  2. CREATE DATABASE inventory;
  3. -- Alters the database to set properties `Edited-by` and `Edit-date`.
  4. ALTER DATABASE inventory SET DBPROPERTIES ('Edited-by' = 'John', 'Edit-date' = '01/01/2001');
  5. -- Verify that properties are set.
  6. DESCRIBE DATABASE EXTENDED inventory;
  7. +-------------------------+------------------------------------------+
  8. |database_description_item| database_description_value|
  9. +-------------------------+------------------------------------------+
  10. | Database Name| inventory|
  11. | Description| |
  12. | Location| file:/temp/spark-warehouse/inventory.db|
  13. | Properties|((Edit-date,01/01/2001), (Edited-by,John))|
  14. +-------------------------+------------------------------------------+
  15. -- Alters the database to set a new location.
  16. ALTER DATABASE inventory SET LOCATION 'file:/temp/spark-warehouse/new_inventory.db';
  17. -- Verify that a new location is set.
  18. DESCRIBE DATABASE EXTENDED inventory;
  19. +-------------------------+-------------------------------------------+
  20. |database_description_item| database_description_value|
  21. +-------------------------+-------------------------------------------+
  22. | Database Name| inventory|
  23. | Description| |
  24. | Location|file:/temp/spark-warehouse/new_inventory.db|
  25. | Properties| ((Edit-date,01/01/2001), (Edited-by,John))|
  26. +-------------------------+-------------------------------------------+