This article describes how to delete a table in MySQL. it is the basic knowledge in MySQ learning. it is easy for anyone who needs to discard a table in MySQL. However, you must be very careful when deleting any existing table and cannot recover it because of data loss.
Syntax:
Below is a general SQL syntax discard (delete) MySQL table:
DROP TABLE table_name ;
Delete a table from a command prompt:
Run the drop table SQL command at the mysql> prompt.
Example:
The following is an example of deleting a table tutorials_tbl:
root@host# mysql -u root -pEnter password:*******mysql> use TUTORIALS;Database changedmysql> DROP TABLE tutorials_tblQuery OK, 0 rows affected (0.8 sec)mysql>
Use a PHP script to delete a MySQL table:
To delete any database in an existing table, you need to use the PHP function mysql_query (). The table will be deleted using the correct SQL command using its second parameter.
Example:
Creating MySQL Tables -by www.bitsCN.com<?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
';$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);?>