Deleting a User from a SQLite Database Based on ID: Practical Implementation

PHOTO EMBED

Tue Jul 09 2024 07:56:38 GMT+0000 (Coordinated Universal Time)

Saved by @freepythoncode ##python #coding #python #programming #sqllite3 #database

import sqlite3

# Connect to the database
con = sqlite3.connect('database.db')

# Create a cursor object
cursor = con.cursor()

# Delete user based on ID
user_id = 123

cursor.execute("DELETE FROM users WHERE id = ?", (user_id,))

# Commit the changes
con.commit()
content_copyCOPY