CSC212 ASSIGNMENT Halve
CSC212 ASSIGNMENT Halve
The Code
import sqlite3
# Connect to SQLite database (or create it if it doesn't exist)
conn = sqlite3.connect('StudentInformationDB.db')
cursor = conn.cursor()
# Insert new student into StudentInfo table
cursor.execute('''
INSERT INTO StudentInfo (FirstName, LastName, DOB, Gender) VALUES (?, ?, ?, ?)
''', ('Cassidy', 'Joel Ogheneyerowo', '2002-03-03', 'M'))
# Get the StudentID of the newly inserted student
student_id = cursor.lastrowid
# Insert registration data into Registration table
cursor.execute('''
INSERT INTO Registration (StudentID, RegistrationDate, Status) VALUES (?, ?, ?)
''', (student_id, '2024-07-16', 'Active'))
# Insert course registrations into CourseRegistration table
courses = ['MTH212', 'MTH213', 'MTH214', 'MTH215']
for course in courses:
cursor.execute('''
INSERT INTO CourseRegistration (StudentID, CourseCode, Semester, Year) VALUES
(?, ?, ?,
?)
''', (student_id, course, 'Fall', 2024))
# Commit the changes
conn.commit()
# Query to show the relationship including the new student
cursor.execute('''
SELECT
si.StudentID,
si.FirstName,
si.LastName,
r.RegistrationID,
r.RegistrationDate,
r.Status, cr.CourseRegistrationID,
cr.CourseCode,
cr.Semester,
cr.Year
FROM
StudentInfo si
JOIN
Registration r ON si.StudentID = r.StudentID
JOIN
CourseRegistration cr ON si.StudentID = cr.StudentID
''')
# Fetch and print the results
rows = cursor.fetchall()
for row in rows:
print(row)
# Close the connection
conn.close()
The Relationship