Recall & Review
beginner
What is a primary key in a database?
A primary key is a unique identifier for each record in a table. It ensures that no two rows have the same value in this column, helping to find data quickly and avoid duplicates.
Click to reveal answer
beginner
What is a foreign key in a database?
A foreign key is a column in one table that links to the primary key in another table. It helps connect related data across tables, like linking a customer to their orders.
Click to reveal answer
intermediate
Why are primary keys important in Supabase tables?
Primary keys in Supabase ensure each row is unique and can be referenced by other tables. This helps keep data organized and supports relationships between tables.
Click to reveal answer
intermediate
How does a foreign key enforce data integrity?
A foreign key makes sure that the value in one table matches a valid primary key in another table. This prevents invalid or orphaned data, keeping the database consistent.
Click to reveal answer
intermediate
Can a table have more than one foreign key? Explain.
Yes, a table can have multiple foreign keys. Each foreign key links to a different table, allowing complex relationships like an order linked to both a customer and a product.
Click to reveal answer
What does a primary key guarantee in a table?
✗ Incorrect
A primary key guarantees that each row in the table has a unique value in that column.
What is the role of a foreign key?
✗ Incorrect
A foreign key links one table to another by referencing the primary key.
In Supabase, what happens if you try to insert a foreign key value that does not exist in the referenced table?
✗ Incorrect
Foreign key constraints prevent inserting invalid references, so the insert fails.
Can a primary key column contain NULL values?
✗ Incorrect
Primary keys must have a value for every row; NULL is not allowed.
Which of these best describes a composite primary key?
✗ Incorrect
A composite primary key uses more than one column to uniquely identify a row.
Explain in your own words what primary keys and foreign keys are and why they matter in a database.
Think about how you would organize a contact list and link it to messages.
You got /4 concepts.
Describe how foreign keys help keep data consistent when you have multiple tables in Supabase.
Imagine you have orders and customers in separate tables.
You got /4 concepts.