Drop Table in MySQL

The article explained the process of creating a table. This article explains how to drop a table from a database. Dropping a table in MySQL is similar to dropping a database. To drop a table in MySQL the following query is used.

DROP TABLE table ;

Drop Table via Object Oriented MySQLi

To drop a Table via MySQLi object in PHP is simple. Pass the query to drop table to the query function of the mysqli object and rest of the process will be done my PHP. The following example demonstrates this concept.




Using MySQLi to Drop MySQL Table



connect_error) {
    die("Connection not established: " . $connection->connect_error);
} 
    
$query = "Use Hospital";
$connection->query($query);
    
// Dropping Table
$query = "DROP Table Patient";
if ($connection->query($query) === TRUE) {
    echo "Table dropped successfuly.";
} else {
    echo "Unable to drop Table " . $connection->error;
}

$connection->close();
?>
        




Download the code

The above code will drop table ‘Patient’ from the ‘Hospital’ database. Remember that you need to switch to ‘Hospital’ database via USE statement and then you can Drop ‘Patient’ table.

Drop Table via Procedural MySQLi

To drop table via MySQLi is very simple. Just replace mysqli object with mysqli_connect function. Take a look at this example.




Using MySQLi to Drop MySQL Table



connect_error) {
    die("Connection not established: " . $connection->connect_error);
} 
    
$query = "Use Hospital";
$connection->query($query);
    
// Dropping Table
$query = "DROP Table Patient";
if ($connection->query($query) === TRUE) {
    echo "Table dropped successfuly.";
} else {
    echo "Unable to drop Table " . $connection->error;
}

$connection->close();
?>
    
    



Download the code

Copyright 2005-2016 KnowledgeHills. Privacy Policy. Contact .