MySQL DROP TABLE Statement

MySQL | DROP TABLE: Learn about the MySQL DROP TABLE Statement, with its explanation, syntax, and query examples.
Submitted by Apurva Mathur, on September 04, 2022

DROP TABLE Statement

The DROP TABLE statement in MySQL deletes the table. It deletes all the rows and columns of the table. Complete data is lost when this statement is hit, so one should be very careful before using this statement.

Note: DROP DATABASE and DROP TABLE statement is different as DROP DATABASE is used to delete the database of the table, which means entire tables which that database contains get deleted, whereas this DROP TABLE statement only deletes the particular table with all its definition and record.

DROP TABLE Statement Syntax

DROP TABLE table_name;

DROP TABLE Statement in MySQL Command-Line Client

First, let us see how we will delete the table in the MySQL command-line client.

Suppose we have a database named "new_schooldb" and inside this database, we have two tables: "Student_details" and "student_subjects",

DROP TABLE Statement (Step 1)

And now if I want to delete the table named "student_subjects" then we'll write the following query;

DROP TABLE student_subjects;
DROP TABLE Statement (Step 2)

As you can see after hitting the query your table named student_subjects is deleted.

Points to keep in mind while deleting any table:

  • Your table name should be in the same case as the original name while writing the query else it will show you an error.
  • The table which you want to delete should be present in the database.
  • Before deleting any table kindly check it, or else your crucial data can be lost.
  • Always select the database first, if you will not select the database then it will show you an error.

DROP TABLE Statement in MySQL Workbench

Now let us see how we drop a table in the MySQL workbench;

Suppose here we have a table named "student_attendance" which we want to delete.

Step 1: Select the table you want to delete.

DROP TABLE Statement (Step 3)

Step 2: Right-click on the table and click on the Drop table, as shown in the picture.

DROP TABLE Statement (Step 4)

Step 3: After clicking on the drop table, it will ask you following options;

DROP TABLE Statement (Step 5)

Click on Drop now

Step 4: As soon as you will click on drop now, your table will be deleted successfully refresh the page you will see the change.




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.