In Supabase, you want to link two tables: orders and customers. Each order must belong to one customer. Which of the following best describes the role of a foreign key in this relationship?
Think about which table holds the reference to the other to enforce the link.
The foreign key is placed in the orders table pointing to the primary key in customers. This ensures each order is linked to exactly one existing customer.
You have two tables: authors and books. Each author can write many books. Which SQL snippet correctly creates a foreign key in books to link to authors?
The foreign key should be in the table that holds many records.
Since one author can have many books, the books table should have a foreign key author_id referencing authors(id). Option A correctly adds this foreign key.
You want to model a many-to-many relationship between students and courses in Supabase. Which architecture is the best practice?
Many-to-many relationships usually require a separate table to link records.
Many-to-many relationships are best handled by a join table that holds foreign keys to both related tables. This avoids data duplication and maintains integrity.
In Supabase, you want to ensure users can only see their own orders. The orders table has a foreign key user_id referencing users. Which RLS policy correctly enforces this?
Check the condition that matches the current user's ID with the order's user_id.
The policy in option A allows users to select only orders where the user_id matches their authenticated user ID, enforcing row-level security.
You have two tables: projects and tasks. tasks has a foreign key project_id referencing projects with ON DELETE CASCADE. What happens when you delete a project?
Consider what ON DELETE CASCADE means for related records.
The ON DELETE CASCADE option causes all related tasks to be deleted automatically when the parent project is deleted, maintaining referential integrity.