0
0
Supabasecloud~5 mins

Primary keys and foreign keys in Supabase - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AEach row is unique
BAll columns are unique
CData is encrypted
DTable has no rows
What is the role of a foreign key?
ATo uniquely identify rows
BTo speed up queries
CTo store large files
DTo link tables together
In Supabase, what happens if you try to insert a foreign key value that does not exist in the referenced table?
AThe insert succeeds
BThe foreign key is ignored
CThe insert fails with an error
DThe referenced table is updated
Can a primary key column contain NULL values?
ANo, primary keys must be NOT NULL
BOnly if the table is empty
CYes, always
DOnly in foreign key columns
Which of these best describes a composite primary key?
AA foreign key referencing multiple tables
BA primary key made of multiple columns
CA key that encrypts data
DA key that allows duplicates
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.