By default, when you connect to an Impala instance, you begin in a database named default. Issue the statement USE db_name to switch to another database within an impala-shell session. The current database is where any CREATE TABLE, INSERT, SELECT, or other statements act when you specify a table without prefixing it with a database name.
Switching the default database is convenient in the following situations:
- To avoid qualifying each reference to a table with the database name. For example, SELECT * FROM t1 JOIN t2 rather than SELECT * FROM db.t1 JOIN db.t2.
- To do a sequence of operations all within the same database, such as creating a table, inserting data, and querying the table.
To start the impala-shell interpreter and automatically issue a USE statement for a particular database, specify the option -d db_name for the impala-shell command. The -d option is useful to run SQL scripts, such as setup or test scripts, against multiple databases without hardcoding a USE statement into the SQL source.
See CREATE DATABASE Statement for examples covering CREATE DATABASE, USE, and DROP DATABASE.
Cancellation: Cannot be cancelled.