DROP DATABASEDROP DATABASE

删除数据库并从文件系统中删除与该数据库关联的目录。Drops a database and deletes the directory associated with the database from the file system. 如果系统中不存在该数据库,则会引发异常。An exception is thrown if the database does not exist in the system.

语法Syntax

DROP { DATABASE | SCHEMA } [ IF EXISTS ] dbname [ RESTRICT | CASCADE ]

参数Parameters

  • DATABASE | SCHEMADATABASE | SCHEMA

    DATABASESCHEMA 意思是相同的,你都可以使用它们。DATABASE and SCHEMA mean the same thing, either of them can be used.

  • IF EXISTSIF EXISTS

    如果已指定,则仅在数据库存在时才会引发异常。If specified, no exception is thrown when the database does not exist.

  • RESTRICTRESTRICT

    如果已指定,将限制删除非空数据库,并且默认情况下处于启用状态。If specified, will restrict dropping a non-empty database and is enabled by default.

  • CASCADECASCADE

    如果已指定,将删除所有关联的表和函数。If specified, will drop all the associated tables and functions.

示例Examples

-- Create `inventory_db` Database
CREATE DATABASE inventory_db COMMENT 'This database is used to maintain Inventory';

-- Drop the database and it's tables
DROP DATABASE inventory_db CASCADE;

-- Drop the database using IF EXISTS
DROP DATABASE IF EXISTS inventory_db CASCADE;