Home > Database > Mysql Tutorial > 在MySQL中删除表的操作教程_MySQL

在MySQL中删除表的操作教程_MySQL

WBOY
Release: 2016-06-01 13:00:24
Original
952 people have browsed it

丢弃现有MySQL的表是很容易的。但是需要非常小心,删除任何现有的一个表后将无法恢复,因为数据丢失。
语法:

下面是通用的SQL语法丢弃(删除)MySQL表:

DROP TABLE table_name ;

Copy after login

从命令提示符删除表:

只需要在mysql>提示符下执行DROP TABLE SQL命令。
例子:

下面是一个例子,它删除表 tutorials_tbl:

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

Copy after login

使用PHP脚本删除MySQL表:

要删除一个现有的表中的任何数据库中,将需要使用PHP函数mysql_query()。将通过它的第二个参数,正确的SQL命令删除表。
例子:

<html>
<head>
<title>Creating MySQL Tables -by www.bitsCN.com</title>
</head>
<body>
<&#63;php
$dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = 'rootpassword';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
 die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully<br />';
$sql = "DROP TABLE tutorials_tbl";
mysql_select_db( 'TUTORIALS' );
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
 die('Could not delete table: ' . mysql_error());
}
echo "Table deleted successfully\n";
mysql_close($conn);
&#63;>
</body>
</html>

Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template