SQL CREATE Database

    The first step of using SQL is creating a Database , and in Relational Database Management System to create a Database we use the CREATE SQL command. As in the previous SQL tutorials we have mentioned that we cannot have two databases with a similar name so before you name your database make sure that the similar name database does not exist in your SQL.

    Check All the present Database

    To list all the existing database, we use the SHOW DATABASE command, and this command list all the databases stored in your RDBMS. Example

    SHOW DATABASES;

    Output

    +--------------------+
    | Database           |
    +--------------------+
    | contacts           |
    | information_schema |
    | music              |
    | mysql              |
    | performance_schema |
    | sys                |
    | world              |
    +--------------------+
    7 rows in set (0.23 sec)

    Create a Database

    Once you have checked that your database similar name does not exist in the current list of databases, now you are good to go to create one. To create a new Database, we use the CREATE DATABASE command along with the Database name. Example

    CREATE DATABASE STUDENT_DB;

    Output

    Query OK, 1 row affected (0.77 sec)

    Verify that your Database

    To check whether your Databases have been created or not, use SHOW DATABASES Command. Example

    SHOW DATABASES;

    Output

    +--------------------+
    | Database           |
    +--------------------+
    | contacts           |
    | information_schema |
    | music              |
    | mysql              |
    | performance_schema |
    | student_db         |
    | sys                |
    | world              |
    +--------------------+
    8 rows in set (0.00 sec)

    Create a Database Quick Summary:

    • To create a Database, we use CREATE DATABASE command;
    • SHOW DATABASES command is used to list all the existing databases.
    • Two databases cannot have similar names.

    People are also reading: