0% found this document useful (0 votes)
38 views15 pages

Page 1 of 15

Uploaded by

ahmedch82281
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)
38 views15 pages

Page 1 of 15

Uploaded by

ahmedch82281
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/ 15

Page 1 of 15

ER DIAGRAM

Entities with Their Attributes

College

 College id (PK)
 Name

Department

 Department ID (PK)
 Department Name
 College ID (FK)

Course

 Course ID (PK)
 Title
 Teacher ID (FK)
 Department ID (FK)

Teachers

 Teacher ID (PK)
 Name
 Email
 Department ID (FK)

Students

 Student ID (PK)
 Name
 Email
 Department ID (FK)

Entities Relationship
College:

 Student Studies in a college.


 Department belongs to college.

Department:

Page 2 of 15
 Belongs to a college.
 Offers multiple courses.
 Has multiple teachers.
 Has multiple students.

Course:

 Belongs to a department.
 Is taught by a teacher.
 Has multiple students enrolled (via enrollments).

Teachers:

 Belongs to a department.
 Teaches multiple courses.

Students:

 Belongs to a department.
 Studies in a college.
 Enrolls in multiple courses (via enrollments).

The underlined attribute for each entities represent their Primary Key.

Challenges Faced
The major challenge was to understand the use case model and to construct an er diagram
from it. Understanding the use case model and relating it to the real-life examples and then
draw an er diagram which truly depicts an er diagram. Then the next challenge was the
attributes of entities and how they would relate to each other and in the end refining or
normalizing them to 3nf was something that demanded a lot of concentration and focus.

Page 3 of 15
Page 4 of 15
NORMALIZATION
In Normalization the shaded box in each table represents primary key and all the tables are in
3nf as they only depend on the primary key. A new Table named Enrollments was formed in
the process of making normalized tables

STUDENT TABLE

std_id Name Email dept_id

COLLEGE TABLE

college_id name

DEPARTMENT TABLE

dept_id name college_id

TEACHER TABLE

teacher_id name email course_id dept_id

COURSE TABLE

course_id title description teacher_id dept_id

ENROLLMENT TABLE

enroll_id grade course_id std_id

Page 5 of 15
DATABASE IMPLEMENTATION
Below is the photo given from a DB Browser for SQLite in which all the required code was
implemented. Necessary attributes were also added keeping in mind the use case model.
PHOTOS FROM DB BROWSER FOR SQLITE

Page 6 of 15
CODE

-- College Table
CREATE TABLE College (
college_id INTEGER PRIMARY KEY,
name TEXT NOT NULL
);

-- Department Table
CREATE TABLE Department (
department_id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
college_id INTEGER,
FOREIGN KEY (college_id) REFERENCES College(college_id)
);

-- Course Table
CREATE TABLE Course (
course_id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
description TEXT,
teacher_id INTEGER,
department_id INTEGER,
FOREIGN KEY (teacher_id) REFERENCES Teacher(teacher_id),
FOREIGN KEY (department_id) REFERENCES Department(department_id)
);

Page 7 of 15
-- Teacher Table
CREATE TABLE Teacher (
teacher_id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL,
department_id INTEGER,
FOREIGN KEY (department_id) REFERENCES Department(department_id)
);

-- Student Table
CREATE TABLE Student (
student_id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL,
department_id INTEGER,
FOREIGN KEY (department_id) REFERENCES Department(department_id)
);

-- Enrollment Table
CREATE TABLE Enrollment (
enrollment_id INTEGER PRIMARY KEY,
student_id INTEGER,
course_id INTEGER,
grade TEXT,
FOREIGN KEY (student_id) REFERENCES Student(student_id),
FOREIGN KEY (course_id) REFERENCES Course(course_id)
);

Page 8 of 15
Code
-- Insert sample data into College Table
INSERT INTO College (name) VALUES ('Engineering College');
INSERT INTO College (name) VALUES ('Arts College');

-- Insert sample data into Department Table


INSERT INTO Department (name, college_id) VALUES ('Computer Science', 1);
INSERT INTO Department (name, college_id) VALUES ('Mathematics', 1);
INSERT INTO Department (name, college_id) VALUES ('History', 2);

-- Insert sample data into Teacher Table


INSERT INTO Teacher (name, email, department_id) VALUES ('Dr. Alice',
'[email protected]', 1);

Page 9 of 15
INSERT INTO Teacher (name, email, department_id) VALUES ('Dr. Bob',
'[email protected]', 2);
INSERT INTO Teacher (name, email, department_id) VALUES ('Dr. Carol',
'[email protected]', 3);

-- Insert sample data into Student Table


INSERT INTO Student (name, email, major, department_id) VALUES ('John
Doe', '[email protected]', 'Computer Science', 1);
INSERT INTO Student (name, email, major, department_id) VALUES ('Jane
Smith', '[email protected]', 'Mathematics', 2);
INSERT INTO Student (name, email, major, department_id) VALUES ('Emily
Brown', '[email protected]', 'History', 3);

-- Insert sample data into Course Table


INSERT INTO Course (title, description, teacher_id, department_id) VALUES
('Database Systems', 'Introduction to Databases', 1, 1);
INSERT INTO Course (title, description, teacher_id, department_id) VALUES
('Calculus', 'Introduction to Calculus', 2, 2);
INSERT INTO Course (title, description, teacher_id, department_id) VALUES
('World History', 'History of the world', 3, 3);

-- Insert sample data into Enrollment Table


INSERT INTO Enrollment (student_id, course_id, grade) VALUES (1, 1, 'A');
INSERT INTO Enrollment (student_id, course_id, grade) VALUES (2, 2, 'B');
INSERT INTO Enrollment (student_id, course_id, grade) VALUES (3, 3, 'A');

Below are the tables after being populated with the sample data. Note that these tables are
before any manipulation tasks were being performed on them which were given in the next
part of the question which include SELECTION, INSERTION and UPDATION.
STUDENT TABLE

Page 10 of 15
std_id Name Email dept_id (FK)

1 John Doe [email protected] 1

2 Jane Smith [email protected] 2

3 Emily Brown [email protected] 3

COLLEGE TABLE

college_id (PK) name

1 Engineering College

2 Arts College

DEPARTMENT TABLE

dept_id (PK) name college_id (FK)

1 Computer Science 1

2 Mathematics 1

3 History 2

TEACHER TABLE

teacher_id (PK) name email dept_id (FK)

1 Dr. Alice [email protected] 1

2 Dr. Bob [email protected] 2

3 Dr. Carol [email protected] 3

COURSE TABLE

course_id (PK) title description teacher_id dept_id (FK)


(FK)
1 Database Systems Introduction to 1 1
Databases
2 Calculus Introduction to 2 2
Calculus

Page 11 of 15
3 World History History of the world 3 3

ENROLLMENT TABLE

enroll_id (PK) grade course_id (FK) std_id (FK)

1 1 1 A

2 2 2 B

3 3 3 C

INSERT QUERIES:
1. A new student has joined so we need to add that student data into students table
INSERT INTO Students (name, email, dept_id) VALUES ('Alice Johnson',
'[email protected]', 1);
2. A new teacher has been hired so there is a need of additional row in the teachers
table.
INSERT INTO Teachers (name, email, dept_id) VALUES (Mitchel Johnson',
'[email protected]', 1);
UPDATE QUERIES:
1. A Student changes his department:
A very often or normal activity in schools when students change their departments so
to perform this action below query will be implemented on our database.

UPDATE Student SET department_id=2 WHERE student_id=3

2. A Course has been assigned to a teacher from a different department


Another very often phenomenon in colleges when subjects overlapped in departments
so teachers are being given subjects of different departments.
UPDATE Course SET teacher_id=1 WHERE course_id=2

SELECT QUERIES:
1. To see which courses have been assigned to a teacher

Page 12 of 15
SELECT course_id, title AS CourseTitle,
(SELECT name FROM Teacher WHERE teacher_id = Course.teacher_id) AS TeacherName
FROM Course;
2. To count the number of departments in college with college_id = 1
This select query selects the number of departments ina college using his id with the help
of COUNT.

SELECT COUNT(department_id) AS NumberOfDepartments


FROM Department
WHERE college_id = 1;

Views
1. View that shows the names of students along with the courses they are enrolled in
and their grades.
Views in SQLite is a virtual table based on the result set of an SQL query. They
dynamically retrieve the data using the stored query. In our example view
“StudentCourses” shows a detailed info about students like a Report Card of a student
showing his name, courses enrolled and the grades he got in those enrolled courses. It
retrieves data from two tables i.e. Student and Course and using join it combines the
data.

CREATE VIEW StudentCourses AS


SELECT
Student.name AS StudentName,
Course.title AS CourseTitle,
Enrollment.grade AS Grade
FROM Enrollment
JOIN Student ON Enrollment.student_id = Student.student_id
JOIN Course ON Enrollment.course_id = Course.course_id;

SELECT * FROM StudentCourses;

Page 13 of 15
2. To view teachers their respective departments along with the courses assigned to
them.
This view gives a detailed info about a teacher showcasing his/her name, department
and the courses assigned to him/her. It retrieves data from three tables aas shown in
the query and then uses join to combine them together.

CREATE VIEW TeacherInfo AS


SELECT
Teacher.name AS TeacherName,
Department.name AS DepartmentName,
Course.title AS CourseTitle
FROM Course
JOIN Teacher ON Course.teacher_id = Teacher.teacher_id
JOIN Department ON Course.department_id = Department.department_id;

SELECT * FROM TeacherInfo;

Security Limitations in SQLite

Lack of User Authentication and Access Control:

Any user with access to the SQLite database file has full access to all the data within
it, which is very alarming that anyone having database access can access the whole
database.

Encryption

SQLite does not support encryption natively. Without encryption, sensitive data stored
in SQLite databases is vulnerable to unauthorized access if the database file is
compromised. Third-party encryption solutions does the work but they add
complexity to the project.

Concurrency Limitations in SQLite

Limited Concurrent Write Support:

SQLite uses a file-level locking mechanism to manage concurrent access, which can
limit the number of simultaneous writes. SQLite allows multiple readers but only one

Page 14 of 15
writer at a time. Applications requiring high write throughput may experience
performance degradation.

No Built-in Replication:

SQLite does not support built-in replication or clustering, which are features
commonly found in other database systems to enhance availability and scalability.

Page 15 of 15

You might also like