PMC: Table relationships
📖 Scenario: You are building a simple online store database using Supabase. You want to connect two tables: customers and orders. Each order belongs to one customer. This relationship helps you find all orders made by a customer.
🎯 Goal: Create two tables in Supabase: customers and orders. Then, set up a foreign key relationship from orders.customer_id to customers.id to link orders to customers.
📋 What You'll Learn
Create a
customers table with columns id (primary key) and name (text).Create an
orders table with columns id (primary key), customer_id (foreign key), and product (text).Add a foreign key constraint on
orders.customer_id referencing customers.id.Use SQL commands valid in Supabase/PostgreSQL.
💡 Why This Matters
🌍 Real World
Table relationships are essential in databases to connect related data, like customers and their orders in an online store.
💼 Career
Understanding how to create and use foreign keys is a key skill for database administrators and backend developers working with cloud databases like Supabase.
Progress0 / 4 steps