Drop MySQL Tables

Drop MySQL Tables

It is very easy to drop an existing MySQL table, but you need to be very careful while deleting any existing table because the data lost will not be recovered after deleting a table.

Syntax

Here is a generic SQL syntax to drop a MySQL table −

<title>Deleting Table in Mysql</title>
close();
?>

Dropping Tables from the Command Prompt

To drop tables from the command prompt, we need to execute the DROP TABLE SQL command at the mysql> prompt.

Example

The following program is an example which deletes the tutorials_tbl −

root@host# mysql -u root -p
Enter password:
mysql> use mydb;
Database changed
mysql> DROP TABLE employee;
Query OK, 0 rows affected (0.27 sec)
mysql>

Dropping Tables Using PHP Script

To drop an existing table in any database, you would need to use the PHP function mysqli_query(). You will pass its second argument with a proper SQL command to drop a table.

Example

<title>Deleting Table in Mysql</title>
close();
?>
Create MySQL Tables (Prev Lesson)
(Next Lesson) MySQL – Insert Query