Help Center/ Document Database Service/ User Guide/ Database Usage/ Creating a Database Using Commands
Updated on 2023-03-15 GMT+08:00

Creating a Database Using Commands

A database is a collection of tables, indexes, views, stored procedures, and operators. To make it easier to manage DDS DB instances, you can create a database by running commands on the newly-created DB instance. If the database does not exist, create the database and switch to the new database. If the database exists, directly switch to the database.

Prerequisites

A DDS instance has been connected. For details, see "Connecting to an Instance over a Public Network" and "Connecting to an Instance over a Private Network" in Document Database Service Getting Started.

Procedure

  1. Create a database.

    use dbname

    dbname: indicates the name of the database to be created.

    Figure 1 Creating databases

  2. After a database is created, insert data into the database so that you can view the database in the database list.

    Figure 2 Inserting data
    There are three system databases created by default: admin, local, and test. If you directly insert data without creating a database, the data is inserted to the test database by default.
    Figure 3 Viewing the database

  3. View data in the database.

    Figure 4 Viewing data