Recall & Review
beginner
What is a FOREIGN KEY constraint in a database?
A FOREIGN KEY constraint is a rule that links one table's column to another table's primary key column. It ensures that the value in the foreign key column matches a value in the referenced table, keeping data consistent.
Click to reveal answer
beginner
Why do we use FOREIGN KEY constraints?
We use FOREIGN KEY constraints to keep data accurate and connected. They prevent adding values in one table that don't exist in the related table, helping avoid mistakes and keeping relationships clear.
Click to reveal answer
intermediate
What happens if you try to insert a value in a FOREIGN KEY column that does not exist in the referenced table?
The database will reject the insert and show an error because the FOREIGN KEY constraint requires the value to exist in the referenced table to keep data consistent.
Click to reveal answer
intermediate
How do you define a FOREIGN KEY constraint when creating a table?
You define a FOREIGN KEY constraint by specifying the column and the referenced table and column using the syntax: FOREIGN KEY (column_name) REFERENCES referenced_table(referenced_column).
Click to reveal answer
intermediate
Can a FOREIGN KEY column contain NULL values?
Yes, a FOREIGN KEY column can contain NULL values unless you specify NOT NULL. NULL means no link to another table, which is allowed in many cases.
Click to reveal answer
What does a FOREIGN KEY constraint do?
✗ Incorrect
A FOREIGN KEY constraint links a column in one table to a primary key in another table to maintain data consistency.
What happens if you insert a value in a FOREIGN KEY column that does not exist in the referenced table?
✗ Incorrect
The database rejects the insert because the FOREIGN KEY constraint requires the value to exist in the referenced table.
Which SQL keyword is used to define a FOREIGN KEY constraint?
✗ Incorrect
FOREIGN KEY is the keyword used to define a foreign key constraint linking tables.
Can a FOREIGN KEY column have NULL values?
✗ Incorrect
A FOREIGN KEY column can have NULL values unless it is declared NOT NULL.
What is the main purpose of a FOREIGN KEY constraint?
✗ Incorrect
The main purpose of a FOREIGN KEY constraint is to enforce referential integrity between tables.
Explain what a FOREIGN KEY constraint is and why it is important in databases.
Think about how tables stay connected and data stays accurate.
You got /4 concepts.
Describe how to create a FOREIGN KEY constraint when making a new table in SQL.
Remember the syntax FOREIGN KEY (column) REFERENCES table(column).
You got /4 concepts.