A table relationship connects two tables so they can share related data, like linking a list of orders to the customers who made them.
Click to reveal answer
beginner
What is a foreign key in table relationships?
A foreign key is a column in one table that points to the primary key in another table, helping link related data between tables.
Click to reveal answer
intermediate
Explain the difference between one-to-many and many-to-many relationships.
One-to-many means one record in a table relates to many records in another (like one customer has many orders). Many-to-many means records in both tables can relate to many records in the other (like students and classes).
Click to reveal answer
beginner
How does Supabase help manage table relationships?
Supabase lets you define foreign keys and use its interface or SQL to create relationships, making it easy to connect tables and query related data.
Click to reveal answer
beginner
Why are table relationships important in cloud databases?
They keep data organized and connected, reduce duplication, and make it easier to retrieve related information quickly and accurately.
Click to reveal answer
What does a foreign key do in a table relationship?
ALinks a record in one table to a record in another table
BStores large files in the database
CCreates a backup of the table
DDeletes duplicate records automatically
✗ Incorrect
A foreign key connects one table's record to another table's record, establishing a relationship.
Which relationship type means one record relates to many records in another table?
AOne-to-one
BMany-to-many
COne-to-many
DNo relationship
✗ Incorrect
One-to-many means one record in a table connects to many records in another table.
In Supabase, how can you create a table relationship?
ABy defining a foreign key between tables
BBy uploading CSV files
CBy changing the database password
DBy deleting tables
✗ Incorrect
Defining foreign keys is how you create relationships between tables in Supabase.
Why are table relationships useful?
AThey remove all data duplication automatically
BThey increase the size of the database
CThey slow down queries
DThey help organize and connect data efficiently
✗ Incorrect
Table relationships organize data and connect related information for efficient use.
What is a many-to-many relationship example?
AOne product belongs to one category
BStudents enroll in many classes, and classes have many students
COne customer has many orders
DOne employee has one ID
✗ Incorrect
Many-to-many means both sides can have many related records, like students and classes.
Describe how foreign keys create relationships between tables in Supabase.
Think about how one table points to another.
You got /4 concepts.
Explain the difference between one-to-many and many-to-many relationships with examples.
Use simple real-life examples to compare.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of creating table relationships in Supabase?
easy
A. To store files in the database
B. To connect data across tables using keys
C. To increase the size of the database
D. To change the database theme
Solution
Step 1: Understand table relationships
Table relationships link data in different tables using keys to keep data connected.
Step 2: Identify the purpose
This linking helps to find related data easily, like joining customer info with orders.
Final Answer:
To connect data across tables using keys -> Option B
Quick Check:
Table relationships = Connect data [OK]
Hint: Relationships link tables by keys for easy data access [OK]
Common Mistakes:
Thinking relationships store files
Believing relationships increase database size
Confusing relationships with UI themes
2. Which SQL keyword is used in Supabase to create a foreign key relationship between tables?
easy
A. REFERENCES
B. JOIN
C. SELECT
D. INSERT
Solution
Step 1: Identify the keyword for foreign keys
In SQL, the REFERENCES keyword defines a foreign key that links one table's column to another's primary key.
Step 2: Match with Supabase usage
Supabase uses standard SQL, so REFERENCES is used to create safe links between tables.
Final Answer:
REFERENCES -> Option A
Quick Check:
Foreign key = REFERENCES [OK]
Hint: Use REFERENCES to link tables with foreign keys [OK]
Common Mistakes:
Using JOIN to create relationships (JOIN reads data, doesn't create keys)
Confusing SELECT or INSERT with key creation
3. Given these two tables: CREATE TABLE authors (id SERIAL PRIMARY KEY, name TEXT); CREATE TABLE books (id SERIAL PRIMARY KEY, title TEXT, author_id INT REFERENCES authors(id)); What will this query return? SELECT books.title, authors.name FROM books JOIN authors ON books.author_id = authors.id;
medium
A. A list of books without author names
B. A list of authors without book titles
C. An error because of missing foreign key
D. A list of book titles with their author's names
Solution
Step 1: Understand the table relationship
The books table has a foreign key author_id linking to authors.id, connecting each book to its author.
Step 2: Analyze the JOIN query
The query joins books and authors on matching author_id and id, selecting book titles and author names together.
Final Answer:
A list of book titles with their author's names -> Option D
4. You wrote this table creation: CREATE TABLE orders (id SERIAL PRIMARY KEY, customer_id INT, FOREIGN KEY customer_id REFERENCES customers(id)); Why does this cause an error in Supabase?
medium
A. FOREIGN KEY syntax is incorrect; it needs parentheses around the column
B. customer_id must be TEXT, not INT
C. PRIMARY KEY cannot be SERIAL
D. REFERENCES keyword is not supported
Solution
Step 1: Check FOREIGN KEY syntax
The FOREIGN KEY clause requires parentheses around the column name, like FOREIGN KEY (customer_id).
Step 2: Confirm other parts
customer_id as INT is valid, SERIAL primary key is valid, and REFERENCES is supported in Supabase.
Final Answer:
FOREIGN KEY syntax is incorrect; it needs parentheses around the column -> Option A
Quick Check:
FOREIGN KEY syntax = parentheses needed [OK]
Hint: Put column names in parentheses after FOREIGN KEY [OK]
Common Mistakes:
Omitting parentheses around foreign key column
Changing data type unnecessarily
Thinking REFERENCES is unsupported
5. You want to create a many-to-many relationship between students and courses tables in Supabase. Which setup is best?
hard
A. Add a foreign key column in students pointing to courses
B. Add a foreign key column in courses pointing to students
C. Create a join table with student_id and course_id as foreign keys
D. Merge students and courses into one table
Solution
Step 1: Understand many-to-many relationships
Many-to-many means each student can take many courses and each course can have many students.
Step 2: Choose the correct design
Neither students nor courses alone can hold all links. A join table with student_id and course_id foreign keys connects them properly.
Final Answer:
Create a join table with student_id and course_id as foreign keys -> Option C
Quick Check:
Many-to-many = join table with two foreign keys [OK]
Hint: Use a join table for many-to-many links [OK]
Common Mistakes:
Trying to store many-to-many in one table column
Merging unrelated tables
Using one foreign key only
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.