sql / sqlite.py
Prajapat's picture
Upload 3 files
072b879 verified
raw
history blame contribute delete
849 Bytes
import sqlite3
## connect to sqlite
connection = sqlite3.connect("test.db")
# Create a cursor object to insert record , create table
cursor = connection.cursor()
## create the table
table_info = """
Create table STUDENT(NAME VARCHAR(25),CLASS VARCHAR(25),
SECTION VARCHAR(25)
);
"""
cursor.execute(table_info)
cursor.execute('''Insert Into STUDENT values('sushil','data science','A')''')
cursor.execute('''Insert Into STUDENT values('ravi','data science','B')''')
cursor.execute('''Insert Into STUDENT values('sumit','data science','A')''')
cursor.execute('''Insert Into STUDENT values('rahul','devops','A')''')
cursor.execute('''Insert Into STUDENT values('vikram','devops','A')''')
print("the inserted records are")
data = cursor.execute('''Select * from student''')
for row in data:
print(row)
connection.commit()
connection.close()