Skip to content

Commit 321cff9

Browse files
sharangksandeep-katta
authored andcommitted
[SPARK-28792][SQL][DOC] Document CREATE DATABASE statement in SQL Reference
# Why are the changes needed? Currently Spark lacks documentation on the supported SQL constructs causing confusion among users who sometimes have to look at the code to understand the usage. This is aimed at addressing this issue. ## How was this patch tested? This is just a documentation change, verified manually.
1 parent 63d035a commit 321cff9

1 file changed

Lines changed: 36 additions & 17 deletions

File tree

docs/sql-ref-syntax-ddl-create-database.md

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,57 @@ license: |
2020
---
2121

2222
### Description
23-
Creates a database with the given name. If database with the same name exists an exception will be thrown.
23+
Creates a database with the specified name. If database with the same name already exists, an exception will be thrown.
2424

2525
### Syntax
2626
{% highlight sql %}
27-
CREATE (DATABASE|SCHEMA) [IF NOT EXISTS] database_name
28-
[COMMENT database_comment]
29-
[LOCATION database_directory]
30-
[WITH DBPROPERTIES (property_name=property_value, ...)]
31-
27+
CREATE {DATABASE | SCHEMA} [ IF NOT EXISTS ] database_name
28+
[ COMMENT database_comment ]
29+
[ LOCATION database_directory ]
30+
[ WITH DBPROPERTIES (property_name=property_value [ , ...]) ]
3231
{% endhighlight %}
3332

3433
### Parameters
35-
- ##### ***IF NOT EXISTS***:
36-
Creates a database with the given name if it doesn't exists. If a database with the same name already exists, nothing will happen.
37-
- ##### ***LOCATION***:
38-
Path of the file system in which database to be created. If the specified path does not exist in the underlying file system, this command creates a directory with the path.
39-
- ##### ***COMMENT***:
40-
Description for the Database.
41-
- ##### ***WITH DBPROPERTIES***:
42-
Properties for the database in key-value pair.
34+
<dl>
35+
<dt><code><em>database_name</em></code></dt>
36+
<dd>Specifies the name of the database to be created.</dd>
37+
38+
<dt><code><em>IF NOT EXISTS</em></code></dt>
39+
<dd>Creates a database with the given name if it doesn't exists. If a database with the same name already exists, nothing will happen.</dd>
40+
41+
<dt><code><em>database_directory</em></code></dt>
42+
<dd>Path of the file system in which database to be created. If the specified path does not exist in the underlying file system, this command creates a directory with the path. If location is not specified, database will be created in default warehouse directory.</dd>
43+
44+
<dt><code><em>database_comment</em></code></dt>
45+
<dd>Description for the database.</dd>
46+
47+
<dt><code><em>WITH DBPROPERTIES (property_name=property_value [ , ...])</em></code></dt>
48+
<dd>Properties for the database in key-value pair.</dd>
49+
</dl>
4350

4451
### Examples
4552
{% highlight sql %}
4653
-- Create database `customer_db`. This throws exception if database with name customer_db already exists.
4754
CREATE DATABASE customer_db;
55+
4856
-- Create database `customer_db` only if database with same name doesn't exist.
4957
CREATE DATABASE IF NOT EXISTS customer_db;
50-
-- Create database `customer_db` only if database with same name doesn't exist with `Comments`, `Specific Location` and `Database properties`.
58+
59+
-- Create database `customer_db` only if database with same name doesn't exist with `Comments`,`Specific Location` and `Database properties`.
5160
CREATE DATABASE IF NOT EXISTS customer_db COMMENT 'This is customer database' LOCATION '/user' WITH DBPROPERTIES (ID=001, Name='John');
52-
{% endhighlight %}
5361

62+
-- Verify that properties are set.
63+
DESCRIBE DATABASE EXTENDED customer_db;
64+
+----------------------------+-----------------------------+
65+
| database_description_item | database_description_value |
66+
+----------------------------+-----------------------------+
67+
| Database Name | customer_db |
68+
| Description | This is customer database |
69+
| Location | hdfs://hacluster/user |
70+
| Properties | ((ID,001), (Name,John)) |
71+
+----------------------------+-----------------------------+
72+
{% endhighlight %}
5473

55-
### Related statements.
74+
### Related Statements
5675
- [DESCRIBE DATABASE](sql-ref-syntax-aux-describe-database.html)
5776

0 commit comments

Comments
 (0)