MySQL delete data table
MySQL delete data table
Deleting data table in MySQL is very easy to operate. But you should be very careful when deleting the table, because all data will disappear after executing the delete command.
1. MySQL delete data table command DROP TABLE delete data table
Syntax
The following is the method for deleting MySQL data table General syntax:
DROP TABLE table_name ;
Delete the data table in the command prompt window
In the mysql> command prompt The SQL statement to delete the data table in the window is DROP TABLE :
Example
The following example deletes the data table php_tbl:
root@host# mysql -u root -p Enter password:******* mysql> use php; Database changed mysql> DROP TABLE php_tbl Query OK, 0 rows affected (0.8 sec) mysql>
Related video tutorial recommendations: MySQL delete statement
2. Use PHP script to delete data tables
PHP uses the mysql_query function to delete MySQL data tables.
This function has two parameters and returns TRUE when executed successfully, otherwise it returns FALSE.
h3> Syntax
bool mysql_query( sql, connection );
Description | |
---|---|
Required. Specifies the SQL query to be sent. Note: The query string should not end with a semicolon. | |
Optional. Specifies the SQL connection identifier. If not specified, the last opened connection is used. |
<html> <head> <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 php_tbl"; mysql_select_db( 'php' ); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('数据表删除失败: ' . mysql_error()); } echo "数据表删除成功\n"; mysql_close($conn); ?> </body> </html>##