From d19691f685a93c7e7e37ab7dd246b69ba743c353 Mon Sep 17 00:00:00 2001 From: shivusondur Date: Sat, 24 Aug 2019 07:14:46 +0530 Subject: [PATCH 1/5] Updated the document details --- docs/_data/menu-sql.yaml | 2 ++ docs/sql-ref-syntax-qry-select-usedb.md | 41 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 docs/sql-ref-syntax-qry-select-usedb.md diff --git a/docs/_data/menu-sql.yaml b/docs/_data/menu-sql.yaml index 717911b5a4645..f4a16f60804fc 100644 --- a/docs/_data/menu-sql.yaml +++ b/docs/_data/menu-sql.yaml @@ -139,6 +139,8 @@ url: sql-ref-syntax-qry-select-limit.html - text: Set operations url: sql-ref-syntax-qry-select-setops.html + - text: USE database + url: sql-ref-syntax-qry-select-usedb.html - text: Common Table Expression(CTE) url: sql-ref-syntax-qry-select-cte.html - text: Subqueries diff --git a/docs/sql-ref-syntax-qry-select-usedb.md b/docs/sql-ref-syntax-qry-select-usedb.md new file mode 100644 index 0000000000000..7f640408fbe3a --- /dev/null +++ b/docs/sql-ref-syntax-qry-select-usedb.md @@ -0,0 +1,41 @@ +--- +layout: global +title: USE Database +displayTitle: USE Database +license: | + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--- + +### Description +Set the provided databse as current database. All subsequent commands that do not explicitly +specify a database will use this one. The default current database is default + +### Syntax +{% highlight sql %} +USE dbname +{% endhighlight %} + +### Parameter + + **dbname** + + dbname is used as current database, If the provided database does not exist, an exception is thrown. + + +### Example +{% highlight sql %} +USE userdb +{% endhighlight %} From bec2de3249c5f8542dca3a3f0b2a9c710ecd6ced Mon Sep 17 00:00:00 2001 From: shivusondur Date: Sat, 24 Aug 2019 17:59:19 +0530 Subject: [PATCH 2/5] Updated the document details --- docs/sql-ref-syntax-qry-select-usedb.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/sql-ref-syntax-qry-select-usedb.md b/docs/sql-ref-syntax-qry-select-usedb.md index 7f640408fbe3a..cb0dcd20f317f 100644 --- a/docs/sql-ref-syntax-qry-select-usedb.md +++ b/docs/sql-ref-syntax-qry-select-usedb.md @@ -20,8 +20,8 @@ license: | --- ### Description -Set the provided databse as current database. All subsequent commands that do not explicitly -specify a database will use this one. The default current database is default +Set the provided database as current database. All subsequent queries will resolve +table names to this database if database name is not provided. The default database name is 'default' ### Syntax {% highlight sql %} @@ -32,10 +32,10 @@ USE dbname **dbname** - dbname is used as current database, If the provided database does not exist, an exception is thrown. + dbname is used as current database. If the provided database does not exist, an exception is thrown. ### Example {% highlight sql %} -USE userdb +USE userdb; {% endhighlight %} From 8ebd70a5b81f0cebd88f74aa4eca0e4b3c5a53cd Mon Sep 17 00:00:00 2001 From: shivusondur Date: Mon, 2 Sep 2019 16:48:43 +0530 Subject: [PATCH 3/5] Handled PR according to #25523 PR which is already merged. to make uniform accross all docs --- docs/sql-ref-syntax-qry-select-usedb.md | 32 +++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/docs/sql-ref-syntax-qry-select-usedb.md b/docs/sql-ref-syntax-qry-select-usedb.md index cb0dcd20f317f..2e192e792cbe6 100644 --- a/docs/sql-ref-syntax-qry-select-usedb.md +++ b/docs/sql-ref-syntax-qry-select-usedb.md @@ -20,22 +20,40 @@ license: | --- ### Description -Set the provided database as current database. All subsequent queries will resolve -table names to this database if database name is not provided. The default database name is 'default' +Set the provided database as current database. All subsequent queries that do not explicitly +provide a database will resolve table names to this database. +The default database name is 'default'. ### Syntax {% highlight sql %} -USE dbname +USE database_name {% endhighlight %} ### Parameter - **dbname** - - dbname is used as current database. If the provided database does not exist, an exception is thrown. - +
+
{FROM|IN} database_name
+
+ Name of the database will be used. If the database is not exist exception will be thrown. +
+
### Example {% highlight sql %} +-- Use the 'userdb' which is exist. USE userdb; ++---------+--+ +| Result | ++---------+--+ ++---------+--+ + +-- Use the 'userdb1' which does't exist +USE userdb1; +Error: org.apache.spark.sql.catalyst.analysis.NoSuchDatabaseException: Database 'userdb1' not found;(state=,code=0) {% endhighlight %} + +### Related statements. +- [CREATE DATABASE](sql-ref-syntax-ddl-create-database.html) +- [DROP DATABASE](sql-ref-syntax-ddl-drop-database.html) +- [CREATE TABLE ](sql-ref-syntax-ddl-create-table.html) + From 364e9a53fcf0a21dd842637a4ac3ff53977e89ce Mon Sep 17 00:00:00 2001 From: shivusondur Date: Wed, 18 Sep 2019 22:49:36 +0530 Subject: [PATCH 4/5] Handled the comments --- docs/sql-ref-syntax-qry-select-usedb.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/sql-ref-syntax-qry-select-usedb.md b/docs/sql-ref-syntax-qry-select-usedb.md index 2e192e792cbe6..cc98e82d6990b 100644 --- a/docs/sql-ref-syntax-qry-select-usedb.md +++ b/docs/sql-ref-syntax-qry-select-usedb.md @@ -20,8 +20,9 @@ license: | --- ### Description -Set the provided database as current database. All subsequent queries that do not explicitly -provide a database will resolve table names to this database. +`USE` statement is used to set a current database. After a current database is set, +the unqualified database artifacts such as tables, functions and views that are +referenced by SQLs are resolved from the current database. The default database name is 'default'. ### Syntax @@ -32,9 +33,9 @@ USE database_name ### Parameter
-
{FROM|IN} database_name
+
database_name
- Name of the database will be used. If the database is not exist exception will be thrown. + Name of the database will be used. If the database is not exist an exception will be thrown.
From e370b13c1962ef44ea221e4c25b1d43458c35838 Mon Sep 17 00:00:00 2001 From: Xiao Li Date: Thu, 19 Sep 2019 10:04:06 -0700 Subject: [PATCH 5/5] Update sql-ref-syntax-qry-select-usedb.md --- docs/sql-ref-syntax-qry-select-usedb.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/sql-ref-syntax-qry-select-usedb.md b/docs/sql-ref-syntax-qry-select-usedb.md index cc98e82d6990b..92ac91ac51769 100644 --- a/docs/sql-ref-syntax-qry-select-usedb.md +++ b/docs/sql-ref-syntax-qry-select-usedb.md @@ -20,8 +20,8 @@ license: | --- ### Description -`USE` statement is used to set a current database. After a current database is set, -the unqualified database artifacts such as tables, functions and views that are +`USE` statement is used to set the current database. After the current database is set, +the unqualified database artifacts such as tables, functions and views that are referenced by SQLs are resolved from the current database. The default database name is 'default'. @@ -35,20 +35,20 @@ USE database_name
database_name
- Name of the database will be used. If the database is not exist an exception will be thrown. + Name of the database will be used. If the database does not exist, an exception will be thrown.
### Example {% highlight sql %} --- Use the 'userdb' which is exist. +-- Use the 'userdb' which exists. USE userdb; +---------+--+ | Result | +---------+--+ +---------+--+ --- Use the 'userdb1' which does't exist +-- Use the 'userdb1' which doesn't exist USE userdb1; Error: org.apache.spark.sql.catalyst.analysis.NoSuchDatabaseException: Database 'userdb1' not found;(state=,code=0) {% endhighlight %}