Updating Data

For updating the data in the SQLite3 table we will use the UPDATE statement. We can update single columns as well as multiple columns using the UPDATE statement as per our requirement.

UPDATE table_name SET column1 = value1, column2 = value2,…  
WHERE condition; 

In the above syntax, the SET statement is used to set new values to the particular column, and the WHERE clause is used to select the rows for which the columns are needed to be updated. 

Example: Updating SQLite3 table using Python

Python3




# Import module
import sqlite3
 
# Connecting to sqlite
conn = sqlite3.connect('gfg.db')
 
# Creating a cursor object using
# the cursor() method
cursor = conn.cursor()
 
# Updating
cursor.execute('''UPDATE emp SET lname = "Jyoti" WHERE fname="Rishabh";''')
 
# Commit your changes in the database
conn.commit()
 
# Closing the connection
conn.close()


Output:

SQL using Python

In this article, integrating SQLite3 with Python is discussed. Here we will discuss all the CRUD operations on the SQLite3 database using Python. CRUD contains four major operations – 

Note: This needs a basic understanding of SQL

Here, we are going to connect SQLite with Python. Python has a native library for SQLite3 called sqlite3. Let us explain how it works. 

Similar Reads

Connecting to SQLite Database

To use SQLite, we must import sqlite3....

Cursor Object

...

Executing SQLite3 Queries – Creating Tables

Before moving further to SQLite3 and Python let’s discuss the cursor object in brief....

Inserting into Table

After connecting to the database and creating the cursor object let’s see how to execute the queries....

Fetching Data

...

Updating Data

To insert data into the table we will again write the SQL command as a string and will use the execute() method....

Deleting Data

...

Deleting Table

...