by R4R Team

-For delete any row from the table, we must know about the sql delete query
i.e.
DELETE FROM TABLE WHERE(CONDITION)

Delete a data of them whose age is greator than 15:

program-

import sqlite3

#connect to database
conn=sqlite3.connect('r4rDatabase.db')

#fetch the data from r4rtable
data=conn.execute("select * from r4rtable")
for row in data:
print("nName : ",row[0])
print("Age : ",row[1])
print("Mobile no. :",row[2])

#delete some row
query='delete from r4rtable where(age>15)'
conn.execute(query)

print("After deletion ")

#After deletion fetch data
data=conn.execute("select * from r4rtable")
for row in data:
print("nName : ",row[0])
print("Age : ",row[1])
print("Mobile no. :",row[2])

conn.close()


output-

Name : Amit
Age : 10
Mobile no. : 12345

Name : Ajay
Age : 12
Mobile no. : 15321

Name : Abhay
Age : 20
Mobile no. : 54321

Name : Sita
Age : 10
Mobile no. : 12458

Name : Geetu
Age : 12
Mobile no. : 12345789

After deletion

Name : Amit
Age : 10
Mobile no. : 12345

Name : Ajay
Age : 12
Mobile no. : 15321

Name : Sita
Age : 10
Mobile no. : 12458

Name : Geetu
Age : 12
Mobile no. : 12345789

-In this program, firstly we print all data from the table, then execute the deletion query where age>15, then the row of name is 'abhay' are deletion as shown in above output.




Leave a Comment: