January 2019
Beginner
318 pages
8h 23m
English
To delete a particular record from your table, use a delete statement. We are going to see an example of deleting data. Create a delete_data.py script and write the following content in it:
import MySQLdb as mdbcon_obj = mdb.connect('localhost', 'test_user', 'test123', 'test')cur_obj = con_obj.cursor()cur_obj.execute("DELETE FROM books WHERE Id = 5");try: con_obj.commit()except: con_obj.rollback()
Run the script as follows:
student@ubuntu:~/work/mysql_testing$ python3 delete_data.py
Now, to check whether your record is deleted or not, run the retrieve_data.py script as follows:
student@ubuntu:~/work/mysql_testing$ python3 retrieve_data.pyOutput:(1, 'Fantastic Beasts')(2, 'Lord of the rings')(3, 'Murder on the Orient Express') ...
Read now
Unlock full access