当前位置:网站首页>Deleting a data table in a command prompt window

Deleting a data table in a command prompt window

2022-06-24 05:21:00 User 4988376

MySQL It's very easy to delete a data table in , But you should be very careful when deleting tables , Because after executing the delete command, all data will disappear .

grammar

Here is the deletion MySQL General syntax for data tables :

DROP TABLE table_name ;

Delete the data table in the command prompt window

stay mysql> Delete the data table in the command prompt window SQL Statement for DROP TABLE

example

The following example deletes the data table runoob_tbl:

[email protected]# mysql -u root -p
Enter password:*******
mysql> use RUNOOB;
Database changed
mysql> DROP TABLE runoob_tbl
Query OK, 0 rows affected (0.8 sec)
mysql>

Use PHP Script delete data table

PHP Use mysqli_query Function to delete MySQL Data sheet .

This function takes two arguments , Returns... On successful execution TRUE, Otherwise return to FALSE.

grammar

mysqli_query(connection,query,resultmode);

Parameters

describe

connection

It's necessary . Stipulate what to use MySQL Connect .

query

It's necessary , Specify the query string .

resultmode

Optional . A constant . It can be any of the following values :MYSQLI_USE_RESULT( If you need to retrieve a lot of data , Please use this )MYSQLI_STORE_RESULT( Default )

  • MYSQLI_USE_RESULT( If you need to retrieve a lot of data , Please use this )
  • MYSQLI_STORE_RESULT( Default )

example

The following example uses PHP Script delete data table runoob_tbl:

Delete database

<?php
$dbhost = 'localhost';  // mysql Server host address 
$dbuser = 'root';            // mysql user name 
$dbpass = '123456';          // mysql User name, password 
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die(' The connection fails : ' . mysqli_error($conn));
}
echo ' Successful connection <br />';
$sql = "DROP TABLE runoob_tbl";
mysqli_select_db( $conn, 'RUNOOB' );
$retval = mysqli_query( $conn, $sql );
if(! $retval )
{
  die(' Data table deletion failed : ' . mysqli_error($conn));
}
echo " Data table deleted successfully \n";
mysqli_close($conn);
?>
mysql> show tables;
Empty set (0.01 sec)
原网站

版权声明
本文为[User 4988376]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/08/20210817183810572O.html