Overview of Foreign Key
| StudentID | Name | Age |
|---|---|---|
| 1 | John | 20 |
| 2 | Sarah | 22 |
| 3 | Michael | 21 |
Students
| CourseID | CourseName | StudentID |
|---|---|---|
| 101 | Math | 1 |
| 102 | Physics | 2 |
| 103 | Chemistry | 1 |
| 104 | Biology | 3 |
Courses
In this example:
- In the “Students” table, “StudentID” is the primary key.
- In the “Courses” table, “CourseID” is the primary key, and “StudentID” is a foreign key referencing the “StudentID” column in the “Students” table.
This relationship indicates that a student can enroll in multiple courses, but each course is associated with only one student.
Hints
- CREATE TABLE Employee_Statistics ( Add all the columns here, also create the FK constraint);
- Use LEFT JOIN
- INSERT INTO Employee_Statistics (names of columns)
SELECT column names
FROM Table1
LEFT JOIN
Table2 ON ….
