Latest web development tutorials

MySQL Delete Data Sheet

When deleting data in MySQL tables are very easy to operate, but you then delete table operation to be very careful, because the command to delete all the data will disappear.

grammar

Following is a table of data delete MySQL general syntax:

DROP TABLE table_name ;

Delete data table in the command prompt window

Delete data table SQL statement mysql> command prompt for DROP TABLE:

Examples

The following examples delete data table w3big_tbl:

root@host# mysql -u root -p
Enter password:*******
mysql> use w3big;
Database changed
mysql> DROP TABLE w3big_tbl
Query OK, 0 rows affected (0.8 sec)
mysql>

Use PHP script to delete data tables

PHP MySQL using mysql_query function to delete the data table.

This function has two parameters, in the implementation of successful returns TRUE, otherwise returns FALSE.

h3> Syntax
bool mysql_query( sql, connection );
parameter description
sql Required. SQL query to send provisions. Note: The query string should not end with a semicolon.
connection Optional. Provisions of SQL connection identifier. If not specified, the use of an open connection.

Examples

The following example uses a PHP script to delete data tables w3big_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 w3big_tbl";
mysql_select_db( 'w3big' );
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('数据表删除失败: ' . mysql_error());
}
echo "数据表删除成功\n";
mysql_close($conn);
?>
</body>
</html>