SQL Drop Database
Last Updated :
06 Oct, 2023
In SQL, sometimes there is a need to delete or drop the database on which you are working. Deleting a database means deleting everything which includes all the data such as tables, views, indexes, schemas, constraints, etc. In order to delete a database we use the DROP DATABASE command. We generally delete a database when the database is no longer required and we want to free the memory that the database is consuming.
Syntax:
DROP DATABASE database_name;
Deleting a Database in SQL
If you’re looking forward to erasing the content of your database, just follow the steps below and your database will be permanently deleted.
Step 1: Creating a Database
To drop a database first there should be a database. So we will create a sample database and create a database using the command CREATE DATABASE. As an example, we will create a database named GeeksForGeeks.
Query
CREATE DATABASE GeeksForGeeks;
Output
Creating new database
Step 2: Retrieving List of databases
Now to confirm that the database has been created or not we will use the SHOW DATABASE command which will return a list of all the databases in the system. Now we will check the name of our database i.e. GeeksForGeeks in the list of databases.
Query
SHOW DATABASES;
Output
List of all databases
Step 3: Deleting the Database
Now after verifying that the database has been created successfully, our main task is to drop the database which we have just created so now we will delete the database GeeksForGeeks. In order to delete a entire database we use the DROP DATABASE command.
Query
DROP DATABASE GeeksForGeeks;
Output
Deleting the Database
Step 4: Verifying the deletion
After the database has been deleted/dropped successfully we will now verify that whether the database exist in the system or not. So we will once again use the SHOW DATABASES command and verify that the GeeksForGeeks database has been deleted or not.
Query
SHOW DATABASES;
Output
Deleted successfully
Conclusion
In this article, we have learned how to delete/drop a database on SQL. To summarize the article, we use the DROP DATABASE command to drop a database. We need to delete a database when the database is not required anymore and we want to free our memory. If you are also looking to drop your database then kindly follow the above mentioned steps.
FAQs on SQL Drop Database
Q1. Will dropping a database drop all the tables inside it also?
Answer:
Yes, dropping a database will drop tables, constraints, indexes everything.
Q2. Is MYSQL case sensitive?
Answer:
No MYSQL is not case sensitive, you can type both in uppercase and lowercase letters.
Q3. Is DROP and DELETE command the same?
Answer:
No DROP and DELETE command are not same. DROP command erases everything whereas DELETE command erases specific rows.
Share your thoughts in the comments
Please Login to comment...