- Python 與 MySQL 教程
- Python 與 MySQL - 主頁
- Python 與 MySQL - 概述
- Python 與 MySQL - 環境設定
- Python 與 MySQL 示例
- Python 與 MySQL - 連線資料庫
- Python 與 MySQL - 建立資料庫
- Python 與 MySQL - 刪除資料庫
- Python 與 MySQL - 選擇資料庫
- Python 與 MySQL - 建立表
- Python 與 MySQL - 刪除表
- Python 與 MySQL - 插入記錄
- Python 與 MySQL - 選擇記錄
- Python 與 MySQL - 更新記錄
- Python 與 MySQL - 刪除記錄
- Python 與 MySQL - Where 子句
- Python 與 MySQL - Like 子句
- Python 與 MySQL - 排序資料
- Python 與 MySQL - 使用聯接
- Python 與 MySQL - 執行事務
- Python 與 MySQL - 處理錯誤
- Python 與 MySQL 有用資源
- Python 與 MySQL - 快速指南
- Python 與 MySQL - 有用資源
- Python 與 MySQL - 討論
Python 與 MySQL -刪除表示例
Python 使用 c.execute(q) 函式刪除表,其中 c 是遊標,q 是要執行的刪除查詢。
語法
# execute SQL query using execute() method. cursor.execute(sql)
| 序號 | 引數與描述 |
|---|---|
| 1 | $sql 必需 - 刪除表的 SQL 查詢。 |
示例
嘗試以下示例來刪除表 -
複製並貼上以下示例作為 mysql_example.ty -
#!/usr/bin/python
import MySQLdb
# Open database connection
db = MySQLdb.connect("localhost","root","root@123","TUTORIALS")
# prepare a cursor object using cursor() method
cursor = db.cursor()
# execute SQL query using execute() method.
cursor.execute("Drop Table tutorials_tbl")
print('Table dropped');
# disconnect from server
db.close()
程式碼
執行 mysql_example.py 指令碼使用 python 並驗證輸出。
Table dropped
廣告