- 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是要執行的delete查詢。
語法
# execute SQL query using execute() method. cursor.execute(sql) cursor.commit() # get the record count updated print(mycursor.rowcount, "record(s) affected")
| Sr.編號。 | 引數和說明 |
|---|---|
| 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()
sql = "Delete from tutorials_tbl where tutorial_id = 2"
# execute SQL query using execute() method.
cursor.execute(sql)
db.commit()
# get the record count updated
print(cursor.rowcount, " record(s) affected")
# disconnect from server
db.close()
輸出
使用python執行mysql_example.py指令碼並驗證輸出。
1 record(s) affected
廣告