January 2019
Beginner
318 pages
8h 23m
English
Now, we will see an example of deleting data from a table. We are going to do this using the delete statement. Create a delete_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 = """ DELETE FROM books WHERE author = 'John Smith' """ cur_obj.execute(sql)print("Data deleted successfully !!")
Run the script and you will get the following output:
student@ubuntu:~/work $ python3 delete_data.pyOutput:Data deleted successfully !!
In the preceding example, we deleted a record from a table. We used the delete SQL statement. Now, to check whether the data is deleted successfully or not, run retrieve_data.py or start the SQLite console, ...
Read now
Unlock full access