Article directory
MySQLHow to delete the data table?MySQL databasedelete datatable command/statement/syntax
MySQL delete table
It is very easy to delete data tables in MySQL, but you should be very careful when you delete tables, because all data will disappear after executing the delete command.
grammar
The following is the general syntax for deleting a MySQL table:
DROP TABLE table_name ;
Delete data table in command prompt window
In the mysql> command prompt window delete the data table SQL statement is DROP TABLE :
Examples
The following example deletes the data table chenweiliang_tbl:
root@host# mysql -u root -p Enter password:******* mysql> use chenweiliang; Database changed mysql> DROP TABLE chenweiliang_tbl Query OK, 0 rows affected (0.8 sec) mysql>
Delete datatable using PHP script
PHP uses the mysqli_query function to delete MySQL tables.
The function has two parameters and returns TRUE if the execution is successful, otherwise it returns FALSE.
h3> syntax
mysqli_query(connection,query,resultmode);
参数 | Description |
---|---|
connection | Required.Specifies the MySQL connection to use. |
Query | Required, specifies the query string. |
result mode | Optional.a constant.Can be any of the following values:
|
Examples
The following example uses a PHP script to delete the data table chenweiliang_tbl:
delete data table
<? php $dbhost = 'localhost:3306'; // mysql服务器主机地址 $dbuser = 'root'; // mysql用户名 $dbpass = '123456'; // mysql用户名密码 $conn = mysqli_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('连接失败: ' . mysqli_error($conn)); } echo '连接成功 '; $sql = 'DROP DATABASE chenweiliang'; $retval = mysqli_query( $conn, $sql ); if(! $retval ) { die('删除数据库失败: ' . mysqli_error($conn)); } echo "数据库 chenweiliang 删除成功\n"; mysqli_close($conn); ?>
After successful execution, we can not see the chenweiliang_tbl table by using the following command:
mysql> show tables; Empty set (0.01 sec)
Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "How does MySQL delete data tables? MySQL Database Delete Data Table Command/Statement/Syntax", it will help you.
Welcome to share the link of this article:https://www.chenweiliang.com/cwl-458.html
Welcome to the Telegram channel of Chen Weiliang's blog to get the latest updates!
📚 This guide contains huge value, 🌟This is a rare opportunity, don’t miss it! ⏰⌛💨
Share and like if you like!
Your sharing and likes are our continuous motivation!