Advanced MySQL Lesson 13 of 13
MySQL Final Project — Design a School Enrollment Database
Design and build a complete enrollment database in MySQL — plan the entities, create tables with keys and constraints, insert sample data, write report queries, add a view and a user.
In this project you'll design a real database for a senior high school's enrollment system, the kind used in capstone projects. You'll plan it, create it, fill it with sample data and write the reports the registrar needs.
Step 1: Plan the entities
List the "things" the system tracks and how they relate:
- Students: LRN, name, birthday, sex, contact.
- Strands: STEM, ABM, HUMSS, GAS, TVL-ICT.
- Sections: belong to a strand and grade level, have a capacity and an adviser.
- School years: 2026–2027, etc.
- Enrollments: a student in a section for a school year, with a status.
strands ──< sections ──< enrollments >── students
│
school_years
A student enrolls every year, so enrollment is its own table connecting students, sections and school years. That's a many-to-many relationship resolved with a linking table.
Step 2: Create the tables
CREATE DATABASE enrollment CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE enrollment;
CREATE TABLE strands (
id TINYINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
code VARCHAR(10) NOT NULL UNIQUE,
name VARCHAR(100) NOT NULL
);
CREATE TABLE school_years (
id SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
label CHAR(9) NOT NULL UNIQUE, -- e.g. 2026-2027
is_current BOOLEAN NOT NULL DEFAULT FALSE
);
CREATE TABLE sections (
id SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30) NOT NULL,
grade_level TINYINT UNSIGNED NOT NULL CHECK (grade_level IN (11, 12)),
strand_id TINYINT UNSIGNED NOT NULL,
capacity TINYINT UNSIGNED NOT NULL DEFAULT 40,
adviser VARCHAR(80),
UNIQUE (name, grade_level),
FOREIGN KEY (strand_id) REFERENCES strands(id)
);
CREATE TABLE students (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
lrn CHAR(12) NOT NULL UNIQUE,
last_name VARCHAR(50) NOT NULL,
first_name VARCHAR(50) NOT NULL,
birthday DATE NOT NULL,
sex ENUM('M', 'F') NOT NULL,
mobile VARCHAR(15)
);
CREATE TABLE enrollments (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
student_id INT UNSIGNED NOT NULL,
section_id SMALLINT UNSIGNED NOT NULL,
school_year_id SMALLINT UNSIGNED NOT NULL,
status ENUM('pending', 'enrolled', 'dropped') NOT NULL DEFAULT 'pending',
enrolled_on DATE NOT NULL DEFAULT (CURRENT_DATE),
UNIQUE (student_id, school_year_id), -- one enrollment per student per year
FOREIGN KEY (student_id) REFERENCES students(id),
FOREIGN KEY (section_id) REFERENCES sections(id),
FOREIGN KEY (school_year_id) REFERENCES school_years(id)
);
Notice the rules built into the design: an LRN can't repeat, a section name can't repeat within a grade level, grade level must be 11 or 12, and a student can't be enrolled twice in the same school year.
Step 3: Sample data
INSERT INTO strands (code, name) VALUES
('STEM', 'Science, Technology, Engineering and Mathematics'),
('ABM', 'Accountancy, Business and Management'),
('TVL-ICT', 'Technical-Vocational-Livelihood: ICT');
INSERT INTO school_years (label, is_current) VALUES ('2026-2027', TRUE);
INSERT INTO sections (name, grade_level, strand_id, capacity, adviser) VALUES
('Einstein', 11, 1, 40, 'Ms. Santos'),
('Sy', 11, 2, 40, 'Mr. Reyes'),
('Turing', 11, 3, 35, 'Sir Cruz');
INSERT INTO students (lrn, last_name, first_name, birthday, sex, mobile) VALUES
('136728140001', 'Reyes', 'Ana', '2010-05-14', 'F', '09171234567'),
('136728140002', 'Santos', 'Ben', '2010-09-02', 'M', NULL),
('136728140003', 'Cruz', 'Carla', '2010-01-23', 'F', '09281234567'),
('136728140004', 'Lim', 'Dan', '2009-11-30', 'M', '09391234567');
INSERT INTO enrollments (student_id, section_id, school_year_id, status) VALUES
(1, 1, 1, 'enrolled'), (2, 3, 1, 'enrolled'), (3, 1, 1, 'pending'), (4, 2, 1, 'enrolled');
Step 4: Reports
Class list for a section
SELECT st.lrn, CONCAT(st.last_name, ', ', st.first_name) AS name, st.sex, e.status
FROM enrollments e
JOIN students st ON st.id = e.student_id
JOIN sections se ON se.id = e.section_id
JOIN school_years sy ON sy.id = e.school_year_id
WHERE se.name = 'Einstein' AND sy.is_current
ORDER BY st.last_name, st.first_name;
Output
+--------------+-------------+-----+----------+ | lrn | name | sex | status | +--------------+-------------+-----+----------+ | 136728140003 | Cruz, Carla | F | pending | | 136728140001 | Reyes, Ana | F | enrolled | +--------------+-------------+-----+----------+
Enrollment count and available slots per section
SELECT se.name AS section, s.code AS strand, se.capacity,
COUNT(e.id) AS enrolled,
se.capacity - COUNT(e.id) AS slots_left
FROM sections se
JOIN strands s ON s.id = se.strand_id
LEFT JOIN enrollments e ON e.section_id = se.id AND e.status = 'enrolled'
GROUP BY se.id, se.name, s.code, se.capacity
ORDER BY s.code;
Output
+----------+---------+----------+----------+------------+ | section | strand | capacity | enrolled | slots_left | +----------+---------+----------+----------+------------+ | Sy | ABM | 40 | 1 | 39 | | Einstein | STEM | 40 | 1 | 39 | | Turing | TVL-ICT | 35 | 1 | 34 | +----------+---------+----------+----------+------------+
Pending enrollments to follow up
SELECT CONCAT(st.first_name, ' ', st.last_name) AS student,
COALESCE(st.mobile, '(no mobile)') AS mobile,
e.enrolled_on
FROM enrollments e
JOIN students st ON st.id = e.student_id
WHERE e.status = 'pending';
Step 5: A view and an app user
CREATE VIEW current_roster AS
SELECT sy.label AS school_year, s.code AS strand, se.grade_level, se.name AS section,
st.lrn, st.last_name, st.first_name, e.status
FROM enrollments e
JOIN students st ON st.id = e.student_id
JOIN sections se ON se.id = e.section_id
JOIN strands s ON s.id = se.strand_id
JOIN school_years sy ON sy.id = e.school_year_id
WHERE sy.is_current;
CREATE USER 'enroll_app'@'localhost' IDENTIFIED BY 'Ch4nge-This-Pa55!';
GRANT SELECT, INSERT, UPDATE ON enrollment.* TO 'enroll_app'@'localhost';
The app user can't DELETE or DROP; dropping a student becomes a status change to 'dropped', which keeps the history.
Challenges
- Add a
subjectstable and agradestable (student, subject, quarter, grade). - Write a query that shows each section's boys and girls count.
- Prevent enrolling into a full section with a trigger or a stored procedure.
- Build a PHP page that lists
current_rosterwith a section filter (see the PHP course). - Draw the ER diagram in MySQL Workbench using Database → Reverse Engineer.
What's next?
Congratulations on finishing the MySQL course! 🎉 You can now design and manage a real database. Connect it to a web app with the PHP course, or analyze exported data in the Excel course.
Quick Quiz
Check what you learned. Walang grade ito, practice lang. 🙂
By Sir Reyel · Last updated 2026-12-04