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 | |
|---|---|---|
| 1FOREIGN KEY (studentId) REFERENCES students(studentId) | AThe orders table is created before students, so the table it REFERENCES doesn't exist yet. The primary table must be created first. | |
| 2INSERT INTO orders VALUES (11, 99, 2, 1, '2026-02-20'); | BLinks the studentId column in this table to the studentId key in the students table, so only matching values are accepted | |
| 3The primary table must be created first, so the table with the foreign key has something to REFERENCE | CCREATE TABLE students (studentId INT PRIMARY KEY); CREATE TABLE orders (orderId INT PRIMARY KEY, studentId INT, FOREIGN KEY (studentId) REFERENCES students(studentId)); | |
| 4A foreign key column must have the same data type as the key it references | DIs rejected if no student with studentId 99 exists, because the foreign key needs a matching value | |
| 5CREATE TABLE orders (orderId INT PRIMARY KEY, studentId INT, FOREIGN KEY (studentId) REFERENCES students); | EREFERENCES must name the key field in brackets after the table, such as students(studentId). Without it the database doesn't know which key to link to. | |
| 6CREATE TABLE orders (orderId INT PRIMARY KEY, studentId INT, FOREIGN KEY (studentId) REFERENCES students(studentId)); CREATE TABLE students (studentId INT PRIMARY KEY); | FstudentId INT, FOREIGN KEY (studentId) REFERENCES students(studentId) |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
FOREIGN KEY (field) REFERENCES other_table(field) — Used in CREATE TABLE to link a column to another table's key. The database then only accepts values that match an existing key, so bad links are rejected.FOREIGN KEY (teamId)
REFERENCES teams(id)FOREIGN KEY (teamId)
REFERENCES teams(id)CREATE TABLE players (
teamId INT,
FOREIGN KEY (teamId) REFERENCES teams(id)CREATE TABLE teams (id INT PRIMARY KEY);
CREATE TABLE players (teamId INT,
FOREIGN KEY (teamId) REFERENCES teams(id)CREATE TABLE players (id INT, teamId INT,
FOREIGN KEY (teamId) REFERENCES teams(id)
);