MySQL 刪除資料表

來源:互聯網
上載者:User

標籤:

MySQL 刪除資料表

MySQL中刪除資料表是非常容易操作的, 但是你再進行刪除表操作時要非常小心,因為執行刪除命令後所有資料都會消失。

文法

以下為刪除MySQL資料表的通用文法:

DROP TABLE table_name ;
在命令提示視窗中刪除資料表

在mysql>命令提示視窗中刪除資料表SQL語句為 DROP TABLE 

執行個體

以下執行個體刪除了資料表tutorials_tbl:

[email protected]# mysql -u root -pEnter password:*******mysql> use TUTORIALS;Database changedmysql> DROP TABLE tutorials_tblQuery OK, 0 rows affected (0.8 sec)mysql>
使用PHP指令碼刪除資料表

PHP使用 mysql_query 函數來刪除 MySQL 資料表。

該函數有兩個參數,在執行成功時返回 TRUE,否則返回 FALSE。

h3> 文法

bool mysql_query( sql, connection );
參數 描述
sql 必需。規定要發送的 SQL 查詢。注釋:查詢字串不應以分號結束。
connection 可選。規定 SQL 串連標識符。如果未規定,則使用上一個開啟的串連。
執行個體

以下執行個體使用了PHP指令碼刪除資料表tutorials_tbl:

<html><head><title>Creating MySQL Tables</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>

MySQL 刪除資料表

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.