Updating User Names Based on IDs in SQLite Step by Step Guide

PHOTO EMBED

Tue Jul 09 2024 08:03:01 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()

# Update user name based on ID
user_id = 2
new_name = "John Doe"

cursor.execute("UPDATE users SET name = ? WHERE id = ?", (new_name, user_id))

# Commit the changes
con.commit()
content_copyCOPY