Relationships
Relationships define how tables connect to each other via foreign keys.
Cardinality types
One-to-many (most common)
One row in table A relates to many rows in table B.
Example: One supplier has many products
"Add a supplier_id foreign key to products that references suppliers.id"
One-to-one
One row in table A relates to exactly one row in table B.
Example: One purchase_order has one shipment
"Create a one-to-one relationship between purchase_orders and shipments via purchase_order_id"
Many-to-many
Many rows in table A relate to many rows in table B, via a junction table.
Example: products and warehouses (a product can be stocked in many warehouses, a warehouse holds many products)
"Create a many-to-many relationship between products and warehouses using an inventory junction table with quantity_on_hand"
Defining relationships via chat
The AI understands natural language relationship descriptions:
- "Products belong to one supplier"
- "Purchase orders have many line items"
- "A product can be stocked in many warehouses, and each warehouse holds many products"
- "Add a self-referential relationship to the warehouses table for parent_warehouse_id"
ERD relationship visualization
In the ERD canvas:
- Lines connect related tables
- Crow's foot notation shows cardinality (one side vs. many side)
- FK badge marks foreign key fields in the table node
Foreign key constraints
TalkingSchema generates proper FOREIGN KEY constraints in exported SQL, including ON DELETE and ON UPDATE behavior.
Specify cascade behavior via chat:
"Set ON DELETE CASCADE on purchase_order_items.po_id so deleting a purchase order removes all its line items"
Junction tables (many-to-many)
For many-to-many relationships, TalkingSchema creates a junction table automatically:
CREATE TABLE inventory (
warehouse_id UUID NOT NULL REFERENCES warehouses(warehouse_id) ON DELETE CASCADE,
product_id UUID NOT NULL REFERENCES products(product_id) ON DELETE CASCADE,
quantity_on_hand INTEGER NOT NULL DEFAULT 0,
reorder_point INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY (warehouse_id, product_id)
);
You can add extra fields to junction tables:
"Add a last_counted_at timestamp to the inventory table"