USE Database

Description

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’.

Syntax

  1. USE database_name

Parameter

  • database_name

    Name of the database will be used. If the database does not exist, an exception will be thrown.

Examples

  1. -- Use the 'userdb' which exists.
  2. USE userdb;
  3. -- Use the 'userdb1' which doesn't exist
  4. USE userdb1;
  5. Error: org.apache.spark.sql.catalyst.analysis.NoSuchDatabaseException: Database 'userdb1' not found;
  6. (state=,code=0)