HomeMogDBMogDB StackUqbar
v5.0

Documentation:v5.0

Supported Versions:

Other Versions:

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.
MogDB=# USE db1;
SET
MogDB=# CREATE TABLE test(a text);
CREATE TABLE
MogDB=# INSERT INTO test VALUES('db1');
INSERT 0 1

--Switch to the db2 database.
MogDB=# USE db2;
SET
MogDB=# CREATE TABLE test(a text);
CREATE TABLE
MogDB=# INSERT INTO test VALUES('db2');
INSERT 0 1
MogDB=# select a from db1.test;
  a  
-----
 db1
(1 row)

MogDB=# select a from db2.test;
  a  
-----
 db2
(1 row)

MogDB=# select a from test;
  a  
-----
 db2
(1 row)

--Switch to the db1 database.
MogDB=# USE db1;
SET
MogDB=# select a from test;
  a  
-----
 db1
(1 row)

N/A

Copyright © 2011-2024 www.enmotech.com All rights reserved.