File size: 959 Bytes
8934fc5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import sqlite3
#connect to SQLlite
connection=sqlite3.connect("student.db")
#create a cursor to insert record,create table
cursor=connection.cursor()
#create a table
table_info="""
Create table STUDENT(NAME VARCHAR(25),CLASS VARCHAR(25),
SECTION VARCHAR(25));
"""
#creating the table
cursor.execute(table_info)
#insert some more records
cursor.execute("""Insert Into STUDENT values("Krish","Data Science","A")""")
cursor.execute("""Insert Into STUDENT values("kayal","DevOps","A")""")
cursor.execute("""Insert Into STUDENT values("david","Data Science","B")""")
cursor.execute("""Insert Into STUDENT values("bala","DevOps","A")""")
cursor.execute("""Insert Into STUDENT values("praveen","Data Science","B")""")
#Display the records
print("The inerted records are")
data=cursor.execute("""select * from STUDENT""")
for row in data:
print(row)
#commit the changes in db
connection.commit()
connection.close() |