创建数据库Create Database

CREATE (DATABASE|SCHEMA) [IF NOT EXISTS] db_name
  [COMMENT comment_text]
  [LOCATION path]
  [WITH DBPROPERTIES (key=val, ...)]

创建数据库。Create a database. 如果已存在同名的数据库,则会引发异常。If a database with the same name already exists, an exception is thrown.

IF NOT EXISTS

如果已存在同名的数据库,则不会发生任何操作。If a database with the same name already exists, nothing will happen.

LOCATION

如果基础文件系统中不存在指定的路径,此命令将尝试使用路径创建目录。If the specified path does not already exist in the underlying file system, this command tries to create a directory with the path.

WITH DBPROPERTIES

为数据库指定一个名 key 为的属性,并将属性的值分别设置为 valSpecify a property named key for the database and establish the value for the property respectively as val. 如果 key 已存在,则将覆盖旧值 valIf key already exists, the old value is overwritten with val.

示例Examples

-- Create database `customer_db`. This throws exception if database with name customer_db
-- already exists.
CREATE DATABASE customer_db;

-- Create database `customer_db` only if database with same name doesn't exist.
CREATE DATABASE IF NOT EXISTS customer_db;