1Prarthana's picture
Upload 7 files
ec8d989 verified
raw
history blame contribute delete
924 Bytes
# Import module
import sqlite3
# Connecting to sqlite
conn = sqlite3.connect('test.db')
# Creating a cursor object using the
# cursor() method
cursor = conn.cursor()
# Creating table
table = """CREATE TABLE STUDENT(NAME VARCHAR(255), CLASS VARCHAR(255),
SECTION VARCHAR(255));"""
cursor.execute(table)
# Queries to INSERT records.
cursor.execute('''INSERT INTO STUDENT VALUES ('Krish', 'Data Science', 'A')''')
cursor.execute('''INSERT INTO STUDENT VALUES ('Darius', 'Data Science', 'B')''')
cursor.execute('''INSERT INTO STUDENT VALUES ('Sudhanshu', 'Devops', 'C')''')
cursor.execute('''INSERT INTO STUDENT VALUES ('Vikash', 'Data Science', 'C')''')
# Display data inserted
print("Data Inserted in the table: ")
data = cursor.execute('''SELECT * FROM STUDENT''')
for row in data:
print(row)
# Commit your changes in the database
conn.commit()
# Closing the connection
conn.close()