USE DATABASE
Contents
USE DATABASE#
Syntax#
UseDatabaseStmt ::=
'USE' DBName
DBName ::=
Identifier
The USE statement selects the current database for a user session.
SQL Statement Template#
USE database_name;
Example:#
Create a database db1:
CREATE DATABASE db1;
-- SUCCEED
CREATE DATABASE db2;
-- SUCCEED
Then select db1 as the current database:
USE db1;
-- SUCCEED: Database changed
Create two tables:
CREATE TABLE t1(col0 string);
-- SUCCEED
CREATE TABLE t2(col0 string);
-- SUCCEED
SHOW TABLES;
--------
Tables
--------
t1
t2
--------
2 rows in set
Then select db2 as the current database and view the tables in db2:
USE db2;
-- SUCCEED: Database changed
SHOW TABLES;
--------
Tables
--------
0 row in set