May 15, 2021 MySQL
Deleting data tables in MySQL is very easy to do, but you should be very careful when you delete tables again, because all data disappears after the delete command is executed.
Here's a common syntax for deleting MySQL data tables:
DROP TABLE table_name ;
Remove the data sheet SQL statement as DROP TABLE in the mysql?command prompt window:
The following instances remove the data w3cschool_tbl:
root@host# mysql -u root -p Enter password:******* mysql> use W3CSCHOOL; Database changed mysql> DROP TABLE w3cschool_tbl Query OK, 0 rows affected (0.8 sec) mysql>
PHP uses mysql_query function to remove mySQL data tables.
The function has two arguments that return TRUE if executed successfully, otherwise FALSE is returned.
h3 syntaxbool mysql_query( sql, connection );
Parameters | Describe |
---|---|
Sql | Necessary. S pecify the SQL query to send. Note: The query string should not end with a sign. |
connection | Optional. S pecifies the SQL connection identifier. If not specified, the last open connection is used. |
The following example uses a PHP script to delete the data w3cschool_tbl:
<html> <head> <meta charset="utf-8"> <title>创建 MySQL 数据表</title> </head> <body> <?php $dbhost = 'localhost:3036'; $dbuser = 'root'; $dbpass = 'rootpassword'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('连接失败: ' . mysql_error()); } echo '连接成功<br />'; $sql = "DROP TABLE w3cschool_tbl"; mysql_select_db( 'W3CSCHOOL' ); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('数据表删除失败: ' . mysql_error()); } echo "数据表删除成功\n"; mysql_close($conn); ?> </body> </html>