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
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
- Create a database, for example, testdb, by referring to Example.
- Run the following statement to delete database testdb if it exists:
1
DROP DATABASE IF EXISTS testdb;
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot