In this section, we will figure out how to erase tables.
Table cancellation is simple, yet recall all erased tables are irretrievable. The overall grammar for table erasure is as per the following −
DROP TABLE table_name ;
Two alternatives exist for playing out a table drop: utilize the order quick or a PHP content.
The Command Prompt
At the order brief, just utilize the DROP TABLE SQL order −
root@host# mysql -u root -p
Enter password:*******
mysql> use PRODUCTS;
Database changed
mysql> DROP TABLE products_tbl
mysql> SELECT * from products_tbl
ERROR 1146 (42S02): Table 'products_tbl' doesn't exist
PHP Drop Table Script
PHP gives mysql_query() for dropping tables. Basically pass its second contention the proper SQL order −
<html>
<head>
<title>Create a MariaDB Table</title>
</head>
<body>
<?php
$dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = 'rootpassword';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully<br />';
$sql = "DROP TABLE products_tbl";
mysql_select_db( 'PRODUCTS' );
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not delete table: ' . mysql_error());
}
echo "Table deleted successfully\n";
mysql_close($conn);
?>
</body>
</html>
On fruitful table cancellation, you will see the accompanying yield −
mysql> Table deleted successfully