0% found this document useful (0 votes)
12 views3 pages

CSC212 ASSIGNMENT Halve

Uploaded by

giftkunuba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

CSC212 ASSIGNMENT Halve

Uploaded by

giftkunuba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CSC212 ASSIGNMENT

Registration Student info Course registration


For CSC212 assignment. First name : Cassidy  MTH212
An assignment for database Other names :Joel  MTH213
Ogheneyerowo  MTH214
Date of birth : 2002-03-03  MTH215
Gender : Male

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

The relationship between the tables StudentInfo, Registration, and CourseRegistration


can be
described as follows:StudentInfo Table: This table contains basic information about
students,
including their first name, last name, date of birth, and gender. Each student is uniquely
identified
by the StudentID.Registration Table: This table tracks the registration status of students.
It
includes a unique RegistrationID, the StudentID (which is a foreign key referencing the
StudentInfo
table), the registration date, and the status (e.g., 'Active').CourseRegistration Table:
This table
records the courses each student is registered for. It includes a unique
CourseRegistrationID, the
StudentID (which is a foreign key referencing the StudentInfo table), the course code,
the
semester, and the year.Relationships:One-to-Many Relationship between StudentInfo
and
Registration: Each student can have multiple registration records over time, but each
registration
record belongs to only one student.One-to-Many Relationship between StudentInfo and
CourseRegistration: Each student can register for multiple courses, but each course
registration
record belongs to only one student.

You might also like