Back to home page

OSCL-LXR

 
 

    


0001 ---
0002 layout: global
0003 title: USE Database
0004 displayTitle: USE 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 `USE` statement is used to set the current database. After the current database is set,
0025 the unqualified database artifacts such as tables, functions and views that are 
0026 referenced by SQLs are resolved from the current database. 
0027 The default database name is 'default'.
0028 
0029 ### Syntax
0030 
0031 ```sql
0032 USE database_name
0033 ```
0034 
0035 ### Parameter
0036 
0037 * **database_name**
0038 
0039     Name of the database will be used. If the database does not exist, an exception will be thrown.
0040 
0041 ### Examples
0042 
0043 ```sql
0044 -- Use the 'userdb' which exists.
0045 USE userdb;
0046 
0047 -- Use the 'userdb1' which doesn't exist
0048 USE userdb1;
0049 Error: org.apache.spark.sql.catalyst.analysis.NoSuchDatabaseException: Database 'userdb1' not found;
0050 (state=,code=0)
0051 ```
0052 
0053 ### Related Statements
0054 
0055 * [CREATE DATABASE](sql-ref-syntax-ddl-create-database.html)
0056 * [DROP DATABASE](sql-ref-syntax-ddl-drop-database.html)
0057 * [CREATE TABLE ](sql-ref-syntax-ddl-create-table.html)