Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1CREATE TABLE teachers (teacherId INT PRIMARY KEY, teacherName VARCHAR(50)); | AINSERT INTO teachers SELECT DISTINCT teacherId, teacherName FROM subjects; | |
| 2ALTER TABLE subjects ADD FOREIGN KEY (teacherId) REFERENCES teachers(teacherId); | BLinks the original table to the new table so the data can be joined back together. | |
| 3Check no data is lost after splitting: joining the new tables should give back every original row. | CThe new table has no primary key. Every table made by splitting for 3NF needs its own primary key, such as teacherId INT PRIMARY KEY. | |
| 4Fields that depend on a non-key field (teacherName depends on teacherId, not subjectId) are moved into a new table. | DSELECT * FROM subjects INNER JOIN teachers ON subjects.teacherId = teachers.teacherId; | |
| 5CREATE TABLE teachers (teacherName VARCHAR(50)); | ECreates a new table for fields that depend on a non-key field, with its own primary key. | |
| 6ALTER TABLE subjects DROP COLUMN teacherName; -- before copying it to teachers | FThe field was dropped before its data was copied into the new table, so the teacher names are lost forever. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
3NF — Third normal form: move fields that depend on a non-key field into a new table with its own primary key, then link the tables with a foreign key. Check no data is lost.CREATE TABLE teacher (
teacherId INT PRIMARY KEY,
room VARCHAR(10));ALTER TABLE student
ADD FOREIGN KEY (teacherId)
REFERENCES teacher(teacherId);INSERT INTO teacher(teacherId, room)
SELECT DISTINCT teacherId, room
FROM student_old;SELECT s.name, t.room
FROM student s JOIN teacher t
ON s.teacherId = t.teacherId;ALTER TABLE student
DROP COLUMN room;