在MySQL中刪除表的操作教程
丟棄現(xiàn)有MySQL的表是很容易的。但是需要非常小心,刪除任何現(xiàn)有的一個表后將無法恢復(fù),因?yàn)閿?shù)據(jù)丟失。
語法:
下面是通用的SQL語法丟棄(刪除)MySQL表:
DROP TABLE table_name ;
從命令提示符刪除表:
只需要在mysql>提示符下執(zhí)行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>
使用PHP腳本刪除MySQL表:
要刪除一個現(xiàn)有的表中的任何數(shù)據(jù)庫中,將需要使用PHP函數(shù)mysql_query()。將通過它的第二個參數(shù),正確的SQL命令刪除表。
例子:
<html>
<head>
<title>Creating MySQL Tables -by www.dhdzp.com</title>
</head>
<body>
<?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);
?>
</body>
</html>
相關(guān)文章
Windows10下MySQL5.7.31解壓版安裝與卸載方法
這篇文章主要介紹了Windows10下MySQL5.7.31解壓版安裝與卸載,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-12-12
Mysql連接本地報錯:1130-host?...?is?not?allowed?to?connect?t
這篇文章主要給大家介紹了關(guān)于Mysql連接本地報錯:1130-host?...?is?not?allowed?to?connect?to?this?MySQL?server的解決方法,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2023-03-03
hive從mysql導(dǎo)入數(shù)據(jù)量變多的解決方案
這篇文章主要介紹了hive從mysql導(dǎo)入數(shù)據(jù)量變多的解決方案,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-01-01

