0
0
Supabasecloud~10 mins

Table relationships in Supabase - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a foreign key relationship in Supabase SQL.

Supabase
CREATE TABLE orders (id SERIAL PRIMARY KEY, user_id INTEGER [1] REFERENCES users(id));
Drag options to blanks, or click blank then click option'
AFOREIGN KEY
BUNIQUE
CINDEX
DCONSTRAINT
Attempts:
3 left
💡 Hint
Common Mistakes
Using CONSTRAINT without FOREIGN KEY keyword.
Using INDEX or UNIQUE which do not define relationships.
2fill in blank
medium

Complete the code to create a one-to-many relationship between users and posts.

Supabase
CREATE TABLE posts (id SERIAL PRIMARY KEY, author_id INTEGER [1] users(id));
Drag options to blanks, or click blank then click option'
AREFERENCES
BJOIN
CCONNECTS
DLINKS
Attempts:
3 left
💡 Hint
Common Mistakes
Using JOIN which is for queries, not table definitions.
Using LINKS or CONNECTS which are not SQL keywords.
3fill in blank
hard

Fix the error in the foreign key constraint syntax.

Supabase
ALTER TABLE comments ADD CONSTRAINT fk_post_id FOREIGN KEY (post_id) [1] posts(id);
Drag options to blanks, or click blank then click option'
ALINKS
BCONNECTS
CREFERENCES
DJOINS
Attempts:
3 left
💡 Hint
Common Mistakes
Using LINKS, CONNECTS, or JOINS which are invalid in this context.
4fill in blank
hard

Fill both blanks to create a many-to-many relationship using a join table.

Supabase
CREATE TABLE [1] (user_id INTEGER [2] users(id), role_id INTEGER REFERENCES roles(id));
Drag options to blanks, or click blank then click option'
Auser_roles
BREFERENCES
CFOREIGN KEY
Droles_users
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect table names that don't reflect the relationship.
Using FOREIGN KEY keyword alone without REFERENCES.
5fill in blank
hard

Fill all three blanks to define a composite primary key and foreign keys in a join table.

Supabase
CREATE TABLE [1] (user_id INTEGER [2] users(id), role_id INTEGER REFERENCES roles(id), PRIMARY KEY ([3]));
Drag options to blanks, or click blank then click option'
Auser_roles
BREFERENCES
Cuser_id, role_id
DFOREIGN KEY
Attempts:
3 left
💡 Hint
Common Mistakes
Using FOREIGN KEY keyword without REFERENCES.
Not defining a composite primary key for the join table.