[Python]SQLiteへデータを削除(delete)するサンプル

2021年8月13日

書式
sqlite3.connect(r’dbパス名’)
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# coding: utf-8
import sqlite3
#SQLiteに接続 raw文字列(r)
conn = sqlite3.connect(r'D:\arkgame\study\userinfo.db')
c = conn.cursor()
try:
#delete文を実行する
c.execute("delete from user_tbl where uno=1004")
#例外処理
except sqlite3.Error as e:
print("error",e.args[0])
#コミット、反映
conn.commit()
#接続を閉じる
conn.close()
# coding: utf-8 import sqlite3 #SQLiteに接続 raw文字列(r) conn = sqlite3.connect(r'D:\arkgame\study\userinfo.db') c = conn.cursor() try: #delete文を実行する c.execute("delete from user_tbl where uno=1004") #例外処理 except sqlite3.Error as e: print("error",e.args[0]) #コミット、反映 conn.commit() #接続を閉じる conn.close()
# coding: utf-8
import sqlite3

#SQLiteに接続 raw文字列(r)
conn = sqlite3.connect(r'D:\arkgame\study\userinfo.db')

c = conn.cursor()

try:
     #delete文を実行する
      c.execute("delete from user_tbl where uno=1004")

#例外処理
except sqlite3.Error as e:
      print("error",e.args[0])

#コミット、反映
conn.commit()

#接続を閉じる
conn.close()

 

Python

Posted by arkgame