Table Relationships
Connect tables with foreign keys for one-to-many and many-to-many patterns.
Table Relationships
Relationships connect your tables so you can link related data — like users to their orders, or products to reviews.
A table schema showing a foreign key field linking to another table Foreign key fields link tables together
One-to-many (most common)
One record in table A can have many related records in table B. The foreign key lives on the "many" side.
Example: A user has many orders.
users id (primary key) email (text)
orders id (primary key) user_id (foreign key -> users.id) total (number) status (text)
Each order belongs to one user. Each user can have many orders.
Set up a foreign key
Open the child table
In the schema editor, open the table that will hold the reference (the "many" side — e.g., orders).
Add a field
Add a new field named user_id (convention: singular table name + _id). Set the type to Number.
Enable Foreign Key
Turn on the Foreign Key option and select the referenced table (e.g., users).
Save
Click Save. The relationship is now set up.
Many-to-many
When both sides can have many related records, create a join table with two foreign keys.
Example: Users can bookmark many products, and products can be bookmarked by many users.
bookmarks id (primary key) user_id (foreign key -> users.id) product_id (foreign key -> products.id)
Pro tip
Join tables can hold extra data too. For example, an order_items table connects orders and products but also stores quantity and price_at_purchase.
Cascade options
When you delete a record, what happens to its related records?
| Option | What happens | |-----------|-------------------------------------------------------| | Restrict | Prevents deletion if related records exist (default) | | Cascade | Automatically deletes related records too | | Set Null | Sets the foreign key to null on related records |
Be careful with Cascade
Deleting a user with cascade enabled on orders would also delete all their orders. Use with caution.
Query related data in functions
In your functions, you can get related data two ways:
- Joins — Use a Database Query step with a join to get data from both tables in one query. - Multiple queries — Fetch the parent first, then query related records in a second step. Often simpler to read.
Tables & Fields /database/tables Create and configure tables Functions /flows Build queries with Database Query steps