ICT Sba
ICT Sba
Performance testing
Performance Improvements:
Indexes Added: Indexes on EventID and Grade columns drastically improved query
execution times.
Caching Implemented: Introduced caching for frequently accessed data, resulting in reduced
load times
Initial Response Times
Before optimization, the response times for certain queries were significantly higher due to
inefficient SQL and lack of indexing. Here are the initial metrics:
1. Indexing:
a. An index was created on the EventID column in the Attendance table.
b. Another index was created on the Grade column in the Student table.
2. Query Rewriting:
a. Although no specific query rewrites were performed for these examples, the
optimization focused on ensuring that queries were structured to take
advantage of the newly created indexes.
1
After implementing the indexing and optimizing the queries, the response times improved
significantly:
Security Testing
Security Enhancements:
Access Control Review: Regular audits confirmed that access restrictions were functioning
as intended. (specific views for access controls are listed below)
Input Validation: Enhanced input sanitization methods effectively prevented SQL injection
vulnerabilities.
PHP:
$event_id = mysqli_real_escape_string($conn, $_POST['event_id']);
$query = "SELECT * FROM Attendance WHERE EventID = '$event_id'";
2
M-001 CPU Usage (%) 85% during 70% during Optimizations
peak load peak load reduced CPU
load, allowing
for better
performance
M-001 Active 200 150 Reducing the
Connections connections connections number of
connections
improved
system stability
Pros:
1. Structured Design
The database is neatly organised into specific tables (Teacher, Student, House, Event,
Attendance), which helps reduce redundancy and promotes normalisation.
3. Attendance Tracking
The system effectively tracks student attendance at events, making it easier to monitor
participation.
3
4. Use of Triggers
Triggers help prevent unauthorised changes to attendance statuses after a certain time,
enforcing business rules right at the database level.
Cons:
1. Inconsistent Data Types for Foreign Keys Using VARCHAR for foreign keys can lead to
inconsistencies. It's better to match these with the primary key types in the referenced
tables.
2. Missing Relationships
The "House" table doesn't have a direct connection to the "Student" table, complicating
queries for students by house.
3. AttendanceID Management
The "AttendanceID" is an INT without an auto-increment feature, which could lead to
conflicts or complexity in managing records.
4. Limited Validation
While there’s some validation for “AttendanceStatus,” there are no checks for valid
“HouseID” or “Grade” entries.
Improvements
4
3. Implement Auto-Increment for AttendanceID
Change “AttendanceID” to an auto-incrementing integer to simplify management:
Sql:
AttendanceID INT PRIMARY KEY AUTOINCREMENT,
Sql:
CREATE TABLE Teacher (
TeacherID VARCHAR(50) PRIMARY KEY,
TeacherName VARCHAR(255),
Department VARCHAR(255)
);
5
EventDate DATE,
EventLocation VARCHAR(255),
FixedTimestamp TIMESTAMP,
TeacherID VARCHAR(50),
FOREIGN KEY (TeacherID) REFERENCES Teacher(TeacherID)
);
2. Establishing Relationships
Added a foreign key constraint in the “Student” table to link to the “House” table.
3. Auto-Increment on AttendanceID
Changed “AttendanceID” to “INT PRIMARY KEY AUTOINCREMENT” for easier management.
4. Grade Validation
Added a check constraint in the “Student” table to ensure valid grades (9 to 12).
6
Database security
In order to limit the access rights for specific data in the database to increase its’ security,
utilising views can expose only the necessary information to different job functions while
keeping sensitive datas from being seen. In addition to the revised database above, below
are views that are created designated to the corresponding roles.
Sql:
CREATE VIEW TeacherEvents AS
SELECT E.EventID, E.EventName, E.EventDate, E.EventLocation, A.StudentID,
A.AttendanceStatus
FROM Event E JOIN Attendance A ON E.EventID = A.EventID
WHERE E.TeacherID = CURRENT_USER;
Sql:
CREATE VIEW StudentAttendance AS
SELECT A.EventID, E.EventName, E.EventDate, A.AttendanceStatus
FROM Attendance A JOIN Event E ON A.EventID = E.EventID
WHERE A.StudentID = CURRENT_USER; -- Assuming CURRENT_USER returns the StudentID
of the logged-in student
Sql:
CREATE VIEW AdminFullAccess AS
SELECT T.TeacherName, S.StudentName, S.Grade, S.Class, H.HouseName, E.EventName,
E.EventDate, A.AttendanceStatus
FROM Attendance A JOIN Event E ON A.EventID = E.EventID
JOIN Student S ON A.StudentID = S.StudentID
JOIN Teacher T ON E.TeacherID = T.TeacherID
JOIN House H ON S.HouseID = H.HouseID;
7
View for House Leaders
This view allows house leaders to see attendance data for students in their house only.
Sql:
CREATE VIEW HouseLeaderAttendance AS
SELECT S.StudentName, E.EventName, A.AttendanceStatus
FROM Attendance A JOIN Event E ON A.EventID = E.EventID
JOIN Student S ON A.StudentID = S.StudentID
WHERE S.HouseID = CURRENT_USER;
Use of CURRENT_USER
The use of “CURRENT_USER” assumes that the application has mechanism to set the current
user context.
8
ADD CONSTRAINT chk_Grade CHECK (Grade IN ('9', '10', '11', '12'));
4.Awareness
Raise awareness about phishing attacks and other threats.
9
FixedTimestamp TIMESTAMP,
TeacherID VARCHAR(50),
TeacherName VARCHAR(255),
Department VARCHAR(255)
);
Pros of Denormalisation:
2.Simplified Queries
Queries are simpler and easier to write and understand, as related data is stored together.
Cons of Denormalisation:
10