Mysql drop table sql query

Mysql drop table sql query

Blog Bustle 29/02/2020

We can delete table from database in mysql using drop table sql query. We can also delete multiple tables from database at a time. Be careful before running mysql drop table sql query because we will lose all information stored in table. Remember that before deleting table first we have to select database.

Mysql drop table sql query syntax

1. Delete one table

drop table table_name;

If want to delete table which does not exist in database then we will get 'unknown table' error. So we should use combined syntax of mysql drop table sql query with if exists.

drop table if exists table_name;

2. Delete multiple table

drop table table_1, table_2, table_3, .... ;

You can also use this mysql drop table sql query for deleting multiple tables.

drop table if exists table_1, table_2, table_3, .... ;

For example, i have student database. First i will delete class table from student database. After that i will delete employee and subject table together from student database.

mysql drop table sql query

So we can delete single or multiple tables using mysql drop table sql query.

Points to remember:

1. If we are going to delete table using command line first we have to connect mysql server from command line.

2. Fisrt select database before deleting table otherwise we will get 'no database selected' error.

3. We should have table backup, whom we want to drop, for future use because we will not able to retrieve table data after deleting table.

4. Deleting table from command line is fast process.

Other important links

Create table sql query

Insert query in mysql

Update query in mysql

Delete query in mysql

Select query in mysql

Mysql drop table sql query searches:

Tags: #mysql