Deleting a Database

Function

This statement is used to delete a database.

Syntax

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

Keywords

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

Precautions

Parameters

Table 1 Parameter

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;