January 2019
Beginner
318 pages
8h 23m
English
We can update the data from our table using the update statement. Now, we are going to see an example of updating data. For that, create a update_data.py script and write the following content in it:
import sqlite3con_obj = sqlite3.connect("test.db")with con_obj: cur_obj = con_obj.cursor() sql = """ UPDATE books SET author = 'John Smith' WHERE author = 'J.K Rowling' """ cur_obj.execute(sql)print("Data updated Successfully !!")
Run the script and you will get the following output:
student@ubuntu:~/work $ python3 update_data.pyOutput:Data updated Successfully !!
Now, to check that the data is actually updated or not, you can run retrieve_data.py, or else you can go to the SQLite console and run select * from books;. You will ...
Read now
Unlock full access