SQL DROP or DELETE Database

    Once we have created a database in SQL, we can also delete it by using the SQL DROP command. Syntax follow this syntax to delete a database:

    DROP DATABASE Database_name;

    Example let first create a temporary database.

    CREATE DATABASE temp_db;

    Output

    Query OK, 1 row affected (0.29 sec)

    Verify if the database is created:

    SHOW DATABASES;

    Output

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

    Delete Database using Drop Command

    DROP DATABASE temp_db;

    Output

    Query OK, 0 rows affected (0.18 sec)

    Verify if the Database is deleted

    SHOW DATABASES;

    Output

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

    SQL DROP Quick Summary

    • With the DROP command, we can delete an existing database.
    • While deleting a database make sure that you pass the correct database name, once the database is deleted you will lose all the information of that database.

    People are also reading: