Drop Table and Database in SQL

This post will teach you how to drop a table, truncate a table, and delete a database in SQL. Dropping a table means deleting it, whereas truncating a table means deleting all of its data but not the table itself.

Drop a Table in SQL

SQL provides the DROP TABLE statement to accomplish this task. The following is the general syntax for dropping a table in SQL.

DROP TABLE tableName;

For example, the SQL query below will delete the table "mytable" from the database.

DROP TABLE mytable;

Truncate a Table in SQL

To remove or delete all of the data or records in a table, use the TRUNCATE statement instead of the DROP statement. The general form of the TRUNCATE statement that can be used to truncate a table in SQL is shown below.

TRUNCATE TABLE tableName;

For example, the SQL query below will delete all the records from the table named "student".

TRUNCATE TABLE student;

Drop a Database in SQL

The SQL query for dropping a database looks similar to the SQL query for dropping a table. The only difference is that we must replace TABLE with DATABASE. Here is the general form of the SQL DROP DATABASE statement that is used to drop a database.

DROP DATABASE databaseName;

For example, to drop a database named "fresherearth," use the following SQL query:

DROP DATABASE fresherearth;

That's it. Here I am going to end the SQL tutorial. I hope you like this tutorial 🙂. If you want to explore more about SQL with me or want to explore other topics with me, then please let me know. You can contact us through any of our social media accounts or directly through the email ID. You can find the link to contact us at the bottom of the page. Thank you, and have a great future 👍.

SQL Online Test


« Previous Topic jobails.com »