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

Syntax:

Here is generic SQL syntax to drop a MySQL table:
DROP TABLE table_name ;

Dropping Tables from Command Prompt:

This needs just to execute DROP TABLE SQL command at mysql> prompt.

Example:

Here is an example, which deletes tutorials_tbl:
root@host# mysql -u root -p
Enter password:*******
mysql> use TUTORIALS;
Database changed
mysql> DROP TABLE tutorials_tbl
Query OK, 0 rows affected (0.8 sec)
mysql>

Dropping Tables Using PHP Script:

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

Example:

<html>
<head>
<title>Creating MySQL Tables</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 tutorials_tbl";
mysql_select_db( 'TUTORIALS' );
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not delete table: ' . mysql_error());
}
echo "Table deleted successfully\n";
mysql_close($conn);
?>
</body>
</html>

Comments

Popular posts from this blog

HaydarOrac

HaydarOrac

To manage DNS, we have to create a primary Zone because by default, there are no zones in order to manage the records. Step 1  − To manage DNS, go to Server Manager → Tools → DNS → Right click on “Forward Lookup Zone” → New Zone. Step 2  − Select “Primary Zone” and then click Next. Step 3  − Enter the name of the primary Zone for which you want to manage the records. Step 4  − Select “Create a new file with this filename” option. Step 5  − If you want to update the record of this zone manually, you have to select “Do not allow dynamic Updates”, as shown in the following screenshot. Step 6  − Click the Finish button.