dev.rean.me
database

Student Exam Database Part 2 - Insert Data and Download Example (Video in Khmer)

Step-by-step guide to insert sample data into 4 tables for Student Exam database using MySQL with Foreign Key insertion rules. Video in Khmer.

2026-08-23 ยท 2 min read

Share:

Hello my friend! Today we continue with Part 2 of our Student Exam Database project!

In this Part 2, we will write SQL INSERT INTO statements to populate sample data into all 4 tables (Students, Teachers, Courses, Exam), and learn why insertion order is very important when tables have Foreign Keys! Video tutorial is in Khmer language, very easy to understand! Now let get start!

If you not create tables or insert data yet, please check here first:
๐Ÿ‘‰ Student Exam Database Part 1 - Create Tables in MySQL
๐Ÿ‘‰ Student Exam Database Part 2 - Insert Data and Download Example


๐Ÿ“ ERD Diagram Reference (Table Relationship)

Here is the ER Diagram of our Student Exam Database. It show how 4 tables connect together:

Student Exam ERD Diagram


โš ๏ธ Important Rule: Table Insertion Order!

When your database has Foreign Keys, you cannot insert data into any order you want:

  1. Insert First (Parent Tables): Students and Teachers (they have no Foreign Keys pointing to other tables).
  2. Insert Second (Child Table): Courses (needs teacherID from Teachers).
  3. Insert Last (Junction Table): Exam (needs both studentID from Students and courseID from Courses).

๐Ÿ’ป Sample SQL INSERT Statements

1. Insert Data into Students Table

INSERT INTO Students (studentID, name, gender, dateOfBirth, city) VALUES 
  (1, 'Vannin', 'M', '2000-09-05', 'Battambang'),
  (2, 'Theary', 'M', '1997-04-15', 'Preah Sihanouk'),
  (3, 'Vathana', 'M', '1991-08-01', 'Pailin');

2. Insert Data into Teachers Table

INSERT INTO Teachers (teacherID, name, title) VALUES 
  (1, 'Vorleak', 'Lecturer'),
  (2, 'Chayan', 'Professor'),
  (3, 'Hoymeng', 'Lecturer');

3. Insert Data into Courses Table

INSERT INTO Courses (courseID, courseName, teacherID) VALUES 
  (1, 'Biology', 3),
  (2, 'Chemistry', 1),
  (3, 'Physics', 2);

4. Insert Data into Exam Table

INSERT INTO Exam (studentID, courseID, score) VALUES 
  (1, 1, 5),
  (1, 2, 9),
  (2, 1, 4),
  (3, 3, 9);

๐Ÿ’พ Download Full Sample SQL Data File

You no need type all insert data by hand! Click button below to download complete SQL script file:

โฌ‡๏ธ Download Student Exam Sample Data (.sql file)


๐Ÿ’ก Tip for Database Beginner: In MySQL, date values in INSERT statements must be formatted as 'YYYY-MM-DD' (e.g. '2000-09-05') inside single quotes '...'! If you format date as DD/MM/YYYY, MySQL will throw error or store wrong value!