USE db_name
Function
The USE db_name statement uses the db_name database as the default (current) database for subsequent statements. The database remains the default database until the end of the paragraph, or until a different USE statement is published.
Precautions
N/A
Syntax
USE db_name
Parameter Description
db_name
Database name
Examples
--Switch to the db1 database.
openGauss=# USE db1;
SET
openGauss=# CREATE TABLE test(a text);
CREATE TABLE
openGauss=# INSERT INTO test VALUES('db1');
INSERT 0 1
--Switch to the db2 database.
openGauss=# USE db2;
SET
openGauss=# CREATE TABLE test(a text);
CREATE TABLE
openGauss=# INSERT INTO test VALUES('db2');
INSERT 0 1
openGauss=# select a from db1.test;
a
-----
db1
(1 row)
openGauss=# select a from db2.test;
a
-----
db2
(1 row)
openGauss=# select a from test;
a
-----
db2
(1 row)
--Switch to the db1 database.
openGauss=# USE db1;
SET
openGauss=# select a from test;
a
-----
db1
(1 row)
Helpful Links
N/A
Feedback