Updating A Record
You can even update a record (tuple) in a table
through python script. The following example change the name “Priya” to
“Priyanka” in a record in “student table”
Example
#code for update operation
import sqlite3
#database name to be passed as
parameter
conn =
sqlite3.connect("Academy.db")
#update the student record
conn.execute("UPDATE Student SET
sname ='Priyanka' where Rollno='6'")
conn.commit()
print ("Total number of rows
updated :", conn.total_changes)
cursor = conn.execute("SELECT *
FROM Student")
for row in cursor:
print (row)
conn.close()
OUTPUT
Total number of rows updated : 1
(1, 'Akshay', 'B', 'M', 87.8,
'2001-12-12')
(2, 'Aravind', 'A', 'M', 92.5,
'2000-08-17')
(3, 'BASKAR', 'C', 'M', 75.2,
'1998-05-17')
(4, 'SAJINI', 'A', 'F', 95.6,
'2002-11-01')
(5, 'VARUN', 'B', 'M', 80.6, '2001-03-14')
(6, 'Priyanka', 'A', 'F', 98.6,
'2002-01-01')
(7, 'TARUN', 'D', 'M', 62.3,
'1999-02-01')
Note
Remember throughout this chapter student table
what we have created is taken as example to explain the SQL queries .Example
15.3.2 -2 contain the student table with records.
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.