0
0
SQLquery~5 mins

Foreign key linking mental model in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a foreign key in a database?
A foreign key is a column or set of columns in one table that refers to the primary key in another table. It creates a link between the two tables.
Click to reveal answer
beginner
Why do we use foreign keys?
Foreign keys help keep data consistent by ensuring that the value in one table matches a value in another table. This prevents errors like referencing a non-existent record.
Click to reveal answer
intermediate
How does a foreign key create a mental model of linking tables?
Think of a foreign key as a bridge connecting two tables. It helps you understand how data in one table relates to data in another, like linking a customer to their orders.
Click to reveal answer
intermediate
What happens if you try to insert a foreign key value that doesn't exist in the referenced table?
The database will reject the insert because it violates the foreign key constraint. This keeps data accurate and linked properly.
Click to reveal answer
intermediate
Can a foreign key be null? What does that mean?
Yes, a foreign key can be null if the relationship is optional. It means the record doesn't currently link to any record in the other table.
Click to reveal answer
What does a foreign key in a table do?
AStores duplicate data
BCreates a new table
CDeletes data from another table
DLinks to a primary key in another table
What happens if you insert a foreign key value that does not exist in the referenced table?
AThe database creates a new record automatically
BThe insert is rejected
CThe foreign key value is ignored
DThe database crashes
Which of these best describes a foreign key?
AA unique identifier for a table
BA column that stores text data
CA link to another table's primary key
DA way to speed up queries
Can a foreign key column contain NULL values?
AYes, if the relationship is optional
BNo, it must always have a value
COnly if the primary key is NULL
DOnly in the primary table
What is the main purpose of a foreign key constraint?
ATo enforce data consistency between tables
BTo speed up data entry
CTo allow duplicate records
DTo delete related records automatically
Explain in your own words how a foreign key links two tables in a database.
Think about how one table points to another like a bridge.
You got /3 concepts.
    Describe what happens if you try to add a record with a foreign key value that does not exist in the referenced table.
    Consider the database's role in keeping data accurate.
    You got /3 concepts.