Categories

[MySQL Tutorial 9] Deleting Table

0

In the previous MySQL tutorial on Updating Table, you learnt how to update values inside an existing table. In this tutorial, you will learn how to delete a table you don’t want in the database.

We may need to delete an unwanted table in the database. To delete a table, use drop command. Drop command is also used to delete a database as described in [MySQL Tutorial 3] Creating Database

Let us create a table name “waste” that we’ll be using for checking the drop command. The syntax for drop command is:

Drop table table_name;


For example,

Create table waste (col1 int, col2 int);

Drop table waste;

 

Using PHP:

<?php
$link=mysql_connect('localhost','root','your password');
mysql_select_db('mysql');
echo "connected to mysql"."<br>";
$r=mysql_query('Drop table employee');
if($r)
{
echo "table dropped";
}
else
{
echo "not dropped";
}
?>

The output is:

Now that you know how to delete table, continue with the next tutorial on how to sort your query using WHERE, LIKE and ORDER BY clauses. Also, If you have any queries, please leave a comment below.

Share.

Leave A Reply