Back to home page

OSCL-LXR

 
 

    


0001 ---
0002 layout: global
0003 title: CREATE DATABASE
0004 displayTitle: CREATE DATABASE 
0005 license: |
0006   Licensed to the Apache Software Foundation (ASF) under one or more
0007   contributor license agreements.  See the NOTICE file distributed with
0008   this work for additional information regarding copyright ownership.
0009   The ASF licenses this file to You under the Apache License, Version 2.0
0010   (the "License"); you may not use this file except in compliance with
0011   the License.  You may obtain a copy of the License at
0012  
0013      http://www.apache.org/licenses/LICENSE-2.0
0014  
0015   Unless required by applicable law or agreed to in writing, software
0016   distributed under the License is distributed on an "AS IS" BASIS,
0017   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0018   See the License for the specific language governing permissions and
0019   limitations under the License.
0020 ---
0021 
0022 ### Description
0023 
0024 Creates a database with the specified name. If database with the same name already exists, an exception will be thrown.
0025 
0026 ### Syntax
0027 
0028 ```sql
0029 CREATE { DATABASE | SCHEMA } [ IF NOT EXISTS ] database_name
0030     [ COMMENT database_comment ]
0031     [ LOCATION database_directory ]
0032     [ WITH DBPROPERTIES ( property_name = property_value [ , ... ] ) ]
0033 ```
0034 
0035 ### Parameters
0036 
0037 * **database_name**
0038 
0039     Specifies the name of the database to be created.
0040 
0041 * **IF NOT EXISTS**
0042 
0043     Creates a database with the given name if it does not exist. If a database with the same name already exists, nothing will happen.
0044 
0045 * **database_directory**
0046 
0047     Path of the file system in which the specified database is to be created. If the specified path does not exist in the underlying file system, this command creates a directory with the path. If the location is not specified, the database will be created in the default warehouse directory, whose path is configured by the static configuration spark.sql.warehouse.dir.
0048 
0049 * **database_comment**
0050 
0051     Specifies the description for the database.
0052 
0053 * **WITH DBPROPERTIES ( property_name=property_value [ , ... ] )**
0054 
0055     Specifies the properties for the database in key-value pairs.
0056 
0057 ### Examples
0058 
0059 ```sql
0060 -- Create database `customer_db`. This throws exception if database with name customer_db
0061 -- already exists.
0062 CREATE DATABASE customer_db;
0063 
0064 -- Create database `customer_db` only if database with same name doesn't exist.
0065 CREATE DATABASE IF NOT EXISTS customer_db;
0066 
0067 -- Create database `customer_db` only if database with same name doesn't exist with 
0068 -- `Comments`,`Specific Location` and `Database properties`.
0069 CREATE DATABASE IF NOT EXISTS customer_db COMMENT 'This is customer database' LOCATION '/user'
0070     WITH DBPROPERTIES (ID=001, Name='John');
0071 
0072 -- Verify that properties are set.
0073 DESCRIBE DATABASE EXTENDED customer_db;
0074 +-------------------------+--------------------------+
0075 |database_description_item|database_description_value|
0076 +-------------------------+--------------------------+
0077 |            Database Name|               customer_db|
0078 |              Description| This is customer database|
0079 |                 Location|     hdfs://hacluster/user|
0080 |               Properties|   ((ID,001), (Name,John))|
0081 +-------------------------+--------------------------+
0082 ```
0083 
0084 ### Related Statements
0085 
0086 * [DESCRIBE DATABASE](sql-ref-syntax-aux-describe-database.html)
0087 * [DROP DATABASE](sql-ref-syntax-ddl-drop-database.html)