Count number of row in table sqlite3 python by R4R Team


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])

#count number of row
n=conn.execute('select count(*) from r4rtable')
print("Number of rows :",*n)

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
Number of rows : (5,)

-In this program, we firstly show all data from the table and it is 5 row, but in second method directly we calculated that number of row is 5 judge from (5,)




Leave a Comment: