Parent and Child Tables

Understanding the distinction between parent and child tables is essential for creating effective data relationships in your Knack application.

What You'll Learn

This guide explains the differences between parent (source) and child (target) tables, how they interact, and how to determine which type of table to use for different scenarios.

Table Types Explained

Parent (Source) Tables

Parent tables contain primary (source) records and are referenced by other tables. In a retail store application, for example, a Products table would act as a parent table.

Key characteristics of parent tables:

  • Contain primary (source) records
  • Are referenced by other tables
  • Have incoming connections (other tables connecting to them)

In the example below, the Products table acts as a Parent table that other tables can reference through Connection Fields.

When tables like Sales and Inventory Alerts include Connection Fields linked to Products, they can access and display data from the Products table.

Think of it like the Products table is the source of truth, with Sales and Inventory Alerts "reaching in" to grab the product information they need.

Tip: Parent tables have incoming connections. Other tables are looking into this table for data.

Child (Target) Tables

Child tables connect to parent tables via a connection field and contain related records. Using the retail store example, a Sales table connected to Products would be a child table.

Key characteristics of child tables:

  • Connect to parent tables via a connection field
  • Contain related records
  • Have outgoing connections (connecting to other tables)

When we look at the Sales table, it contains a Connection Field that links out to the Products table.

Think of the Sales table as reaching outward to fetch data from Products - that's why we call it an outgoing connection. The Sales table is the "child" because it depends on and references data from the "parent" Products table.

This means each sales record can automatically pull in relevant product details without duplicating that information across tables.

Tip: Child tables have outgoing connections. They are looking out to other tables to gather data.

Practical Applications

Contact Directory Example

In a Contact Directory application:

  • Companies table (parent) contains company information
  • Contacts table (child) connects to the Companies table
  • Each contact record is connected to a company record

This structure allows you to:

  • View a company record and see all connected contacts
  • Avoid duplicating company information across multiple contact records
  • Maintain consistent company data

Order System Example

In an Order Management system:

  • Products table (parent) contains product information
  • Orders table (child) connects to the Products table
  • Each order can reference multiple products

This setup enables you to:

  • Update product information in one place
  • View all orders associated with a specific product
  • Maintain accurate product information across all orders

Tip: One table can have a variety of connections. In other words, a table could be a parent, child, and/or nested type of table!