Spaces:
Sleeping
Sleeping
import sqlite3 | |
connection = sqlite3.connect("student.db") | |
# Create a Cursor object to execute queries (e.g. insert, record, create table) | |
cursor = connection.cursor() | |
# create table | |
table_info = """ | |
CREATE TABLE student ( | |
NAME VARCHAR(25), | |
CLASS VARCHAR(25), | |
SECTION VARQCHAR(25) | |
); | |
""" | |
cursor.execute(table_info) | |
# insert data | |
cursor.execute("""Insert Into STUDENT values("Hazem", "AI", "A")""") | |
cursor.execute("""Insert Into STUDENT values("Khaled", "AI", "C")""") | |
cursor.execute("""Insert Into STUDENT values("Essam", "AI", "A")""") | |
cursor.execute("""Insert Into STUDENT values("Ahmed", "Data Science", "A")""") | |
cursor.execute("""Insert Into STUDENT values("Mohamed", "Machine Learning", "B")""") | |
cursor.execute("""Insert Into STUDENT values("Mahmoud", "Data Warehouse", "A")""") | |
cursor.execute("""Insert Into STUDENT values("Abdelrahman", "Data Engineering", "C")""") | |
print("Inserted records are") | |
data = cursor.execute("""SELECT * FROM STUDENT""") | |
for row in data: | |
print(row) | |
connection.commit() | |
connection.close() |