English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Deleting a data table in MySQL is very easy to operate, but you must be very careful when performing the delete table operation, because all data will be deleted after executing the delete command.
The following is the general syntax for deleting MySQL data tables:
DROP TABLE table_name ;
The SQL statement to delete a data table in the mysql> command prompt window is DROP TABLE :
The following example deletes the data table w3codebox_tbl:
root@host# mysql -u root -p Enter password:******* mysql> use w3codebox; Database changed mysql> DROP TABLE w3codebox_tbl Query OK, 0 rows affected (0.8 sec) mysql>
PHP uses the mysqli_query function to delete MySQL data tables.
This function has two parameters, and returns TRUE on success, otherwise returns FALSE.
mysqli_query(connection, query, resultmode);
Parameter | Description |
---|---|
connection | Required. Specify the MySQL connection to use. |
query | Required, specify the query string. |
resultmode | Optional. A constant. It can be any of the following values:
|
The following example uses a PHP script to delete the data table w3codebox_tbl:
<?php $dbhost = 'localhost'; // MySQL server host address $dbuser = 'root'; // MySQL username $dbpass = '123456'; // MySQL username password $conn = mysqli_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Connection failed: ' . mysqli_error($conn)); } /> $sql = "DROP TABLE w3codebox_tbl"; mysqli_select_db($conn, 'w3codebox'); $retval = mysqli_query($conn, $sql); if(! $retval ) { die('Table deletion failed: ' . mysqli_error($conn)); } echo "Table deletion successful\n"; mysqli_close($conn); ?>
After the execution is successful, we use the following command to not see w3codebox_tbl table:
mysql> show tables; Empty set (0.01 sec)