Below is the code to create a connection to a database, create a table, insert values in the table, update the records and print the records in the table.


import sqlite3

con = sqlite3.connect ( ' testdb.sqlite3 ' )

cur = con.cursor()

q1 = " create table customer44(cust_no Number ( 10 ) Not Null Primary Key , cust_name Text ( 20 ) ) ; "

q2 = " insert into customer44 values ( 1 , ' rishi ' ) "

q3 = " insert into customer44 values ( 2 , ' rish ' ) "

q4 = " insert into customer44 values ( 3 , ' ris ' ) "

q5 = " insert into customer44 values ( 4 , ' ri ' ) "

q6 = " insert into customer44 values ( 5 , ' r ' ) "

cur.execute( q1 )

print ( " table created " )

cur.execute( q2 )

cur.execute( q3 )

cur.execute( q4 )

cur.execute( q5 )

cur.execute( q6 )

print ( " values entered " )

q7 = " update customer44 set cust_name =  ' RRR ' where cust_no = 1 "

print ( " table updated " )

q10 = " delete from customer44 where cust_no = 2 "

q11 = " select * from customer44 "


cur.execute( q10 )

cur.execute( q11 )

res = cur.fetchall ()

for i in res:

    no = i [ 0 ]

    name = i [ 1 ]

    print ( no , " , " , name )


con.close()