doc-exports/docs/dli/sqlreference/dli_08_0072.html
Su, Xiaomeng 04d4597cf3 dli_sqlreference_0511_version
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
Co-committed-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
2023-11-02 14:34:08 +00:00

5.9 KiB

Deleting a Database

Function

This statement is used to delete a database.

Syntax

1
DROP [DATABASE | SCHEMA] [IF EXISTS] db_name [RESTRICT|CASCADE];

Keyword

IF EXISTS: Prevents system errors if the database to be deleted does not exist.

Precautions

  • DATABASE and SCHEMA can be used interchangeably. You are advised to use DATABASE.
  • RESTRICT: If the database is not empty (tables exist), an error is reported and the DROP operation fails. RESTRICT is the default logic.
  • CASCADE: Even if the database is not empty (tables exist), the DROP will delete all the tables in the database. Therefore, exercise caution when using this function.

Parameters

Table 1 Parameter description

Parameter

Description

db_name

Database name, which consists of letters, digits, and underscores (_). The value cannot contain only digits or start with a digit or underscore (_).

Example

  1. Create a database, for example, testdb, by referring to Example.
  2. Run the following statement to delete database testdb if it exists:
    1
    DROP DATABASE IF EXISTS testdb;