University database (MariaDB): schema, tables and SQL exercises
University is a sample MariaDB database of a university: departments, faculty, students, courses, class sections, enrollments, grades and research.
On SQLtest.online you can query it right in your browser: solve exercises with automatic checking and run your own queries in the playground, with nothing to install.
University is a modern sample database for MariaDB 11, designed as a richer alternative to the classic Sakila. It is normalized to third normal form and uses many MariaDB data types: JSON, ENUM and SET, FULLTEXT indexes and VECTOR columns for embeddings.
The data is large enough for real analytics: about 25 thousand enrollments, 300 thousand grade events and an audit log of more than half a million rows. At the same time the subject is familiar to anyone who has studied at a university.
ER diagram
The diagram shows the University tables and the foreign keys between them. Click it to open the full-size version.
What's inside
The tables fall into three groups.
People and structure
departments (a tree), faculty, students and rooms.
Teaching
courses with course_prerequisites, semesters, sections, enrollments and grade_events.
Research and money
research_projects, project_members, publications, scholarships and student_scholarships, plus audit_log.
The key thing to remember: students enroll in a section, a specific run of a course in a semester, not in the course itself. So the path from a student to a course is enrollments → sections → courses. Seven views, such as v_student_gpa and v_course_pass_rate, contain ready-made reports.
How much data the tables hold:
Table
Rows
Contents
students
2,000
students
faculty
250
teaching staff
departments
25
departments
courses
116
courses
course_prerequisites
49
course prerequisites
semesters
20
semesters
sections
1,715
course sections in a semester
rooms
48
rooms
enrollments
24,981
enrollments in sections
grade_events
307,081
grades for assignments and exams
research_projects
200
research projects
project_members
876
project members
publications
500
publications
scholarships
20
scholarships
student_scholarships
773
scholarships awarded to students
audit_log
664,124
change log
Table structure
Click a table to see its columns, a sample row and its keys.
The list of tables
semesters - academic semester table.
semester_idunique record identifier (PK, TINYINT)
termterm type: Fall, Spring, or Summer (ENUM)
academic_yearacademic year (YEAR)
namesemester name (e.g. 'Fall 2024')
start_datefirst day of the semester
end_datelast day of the semester
enroll_deadlinelast date for student enrollment
is_activewhether the semester is currently active (BOOLEAN)
semester_id
term
academic_year
name
start_date
end_date
enroll_deadline
is_active
1
Fall
2024
Fall 2024
2024-09-02
2024-12-20
2024-09-13
1
PRIMARY KEY, btree (semester_id)
UNIQUE KEY (term, academic_year)
rooms - campus classrooms and labs.
room_idunique record identifier (PK, SMALLINT)
buildingbuilding name
room_numberroom number or label
capacitymaximum number of seats (SMALLINT)
room_typeroom type: lecture, seminar, lab, computer_lab, or online (ENUM)
has_projectorwhether the room has a projector (BOOLEAN)
has_videowhether the room has video conferencing equipment (BOOLEAN)
room_id
building
room_number
capacity
room_type
has_projector
has_video
1
Science Hall
101
120
lecture
1
0
PRIMARY KEY, btree (room_id)
UNIQUE KEY (building, room_number)
scholarships - available scholarships and grants.
scholarship_idunique record identifier (PK, SMALLINT)
namescholarship name
amountaward amount (DECIMAL)
frequencyaward frequency: one-time, annual, or per-semester (ENUM)
eligibilityeligibility criteria as JSON — e.g. {"min_gpa": 3.5, "need_based": true}
is_activewhether the scholarship is currently offered (BOOLEAN)
audit_log - trigger-generated row-level change history (~60 000 rows).
log_idunique record identifier (PK, BIGINT)
table_namename of the modified table
record_idprimary key of the modified record (BIGINT)
actiontype of change: INSERT, UPDATE, or DELETE (ENUM)
changed_atdate and time of the change (TIMESTAMP)
changed_bydatabase user or application context (nullable)
old_valuesprevious column values as JSON (null for INSERT)
new_valuesnew column values as JSON (null for DELETE)
log_id
table_name
record_id
action
changed_at
changed_by
old_values
new_values
1
enrollments
1
UPDATE
2024-12-21 09:05:33
app_user
{"status":"enrolled","final_score":null}
{"status":"completed","final_score":93.50}
PRIMARY KEY, btree (log_id)
Views
v_student_gpa - weighted GPA per student per semester.
student_idstudent identifier
student_numberunique student ID number
first_namestudent's first name
last_namestudent's last name
semester_idsemester identifier
semester_namesemester name
semester_gpaweighted GPA for the semester
credits_earnedcredit hours earned in the semester
student_id
student_number
first_name
last_name
semester_id
semester_name
semester_gpa
credits_earned
1
S000123
James
Miller
1
Fall 2024
3.72
15
v_section_roster - enrolled students with contact info per section.
section_idsection identifier
course_codecourse code
course_titlecourse title
semester_namesemester name
student_idstudent identifier
student_numberunique student ID number
first_namestudent's first name
last_namestudent's last name
emailstudent's email address
statusenrollment status
section_id
course_code
course_title
semester_name
student_id
student_number
first_name
last_name
email
status
1
CS301
Database Systems
Fall 2024
1
S000123
James
Miller
j.miller@student.edu
enrolled
v_course_pass_rate - historical pass/fail percentage and average score per course.
course_idcourse identifier
codecourse code
titlecourse title
semester_idsemester identifier
semester_namesemester name
total_enrolledtotal number of students enrolled
passednumber of students who passed
pass_ratepass rate as a percentage
avg_scoreaverage final score
course_id
code
title
semester_id
semester_name
total_enrolled
passed
pass_rate
avg_score
1
CS301
Database Systems
1
Fall 2024
28
25
89.29
81.40
v_faculty_workload - sections taught and fill rate per faculty member per semester.
faculty_idfaculty member identifier
first_namefaculty member's first name
last_namefaculty member's last name
semester_idsemester identifier
semester_namesemester name
sections_taughtnumber of sections taught
total_capacitytotal seat capacity across all sections
total_enrolledtotal number of enrolled students
fill_ratefill rate as a percentage
faculty_id
first_name
last_name
semester_id
semester_name
sections_taught
total_capacity
total_enrolled
fill_rate
1
Alice
Carter
1
Fall 2024
3
90
82
91.11
v_top_scholars - students ranked by total scholarship funding received.
rank_positionrank by total scholarship amount
student_idstudent identifier
student_numberunique student ID number
first_namestudent's first name
last_namestudent's last name
total_scholarshipsnumber of scholarship awards
total_amounttotal amount_awarded across all scholarships
rank_position
student_id
student_number
first_name
last_name
total_scholarships
total_amount
1
1
S000123
James
Miller
2
8500.00
v_publication_stats - paper count and citations per department per year.
department_iddepartment identifier
department_namedepartment name
pub_yearyear of publication
paper_countnumber of papers published
total_citationstotal citation count across all papers
department_id
department_name
pub_year
paper_count
total_citations
3
Computer Science
2024
12
87
v_prerequisite_tree - direct prerequisites for every course.
course_idcourse identifier
course_codecourse code
course_titlecourse title
prerequisite_idprerequisite course identifier
prerequisite_codeprerequisite course code
prerequisite_titleprerequisite course title
is_mandatorywhether the prerequisite is mandatory or recommended
course_id
course_code
course_title
prerequisite_id
prerequisite_code
prerequisite_title
is_mandatory
5
CS401
Advanced Database Systems
1
CS301
Database Systems
1
Sample queries
These queries show how the data is connected. Copy any of them and run it in the playground.
A student, course and grade: from an enrollment through the section to the course and semester.
SELECT s.first_name, s.last_name, c.code, sem.name AS semester, e.final_grade
FROM enrollments e
JOIN students s ON s.student_id = e.student_id
JOIN sections sec ON sec.section_id = e.section_id
JOIN courses c ON c.course_id = sec.course_id
JOIN semesters sem ON sem.semester_id = sec.semester_id
WHERE e.final_grade IS NOT NULL
ORDER BY e.enrollment_id
LIMIT 3;
first_name
last_name
code
semester
final_grade
Alexis
Collier
MATH111
Fall 2024
B+
Alexis
Collier
NURS102
Fall 2024
B
Alexis
Collier
MATH106
Summer 2024
B
Office hours from JSON: reading a value from a JSON column with JSON_VALUE.
SELECT first_name, last_name,
JSON_VALUE(office_hours, '$[0].day') AS day,
JSON_VALUE(office_hours, '$[0].start') AS starts_at
FROM faculty
ORDER BY faculty_id
LIMIT 3;
first_name
last_name
day
starts_at
Danielle
Johnson
Tue
09:00
Jason
Hahn
Fri
08:00
Kathleen
Cannon
Fri
08:00
SQL exercises by topic
There are 5 exercises on the University database so far, and new ones are being added. Solutions are checked automatically on a real MariaDB server.
The number on the right is how many exercises a topic has; the colored dots show its difficulty range.
Do I need to install MariaDB to use the University database?
No. The exercises and the playground on SQLtest.online run your queries on our servers, so a browser is all you need. In the playground, University is available on MariaDB 11.8.
Which MariaDB features does it use?
JSON columns, ENUM and SET types, FULLTEXT indexes, VECTOR columns for embeddings, views and a department hierarchy for recursive queries.
Can I change the data?
In the playground the database is read-only, so everyone sees the same data. Use a regular MariaDB version in the playground to practice INSERT, UPDATE and DELETE on your own tables.