How to generate synthetic relational data with foreign keys

By the Ground team

Generate primary keys for parent tables first, then sample those keys when creating child rows. Derive totals from the generated children and run integrity queries before importing.

Model relationships explicitly

Specify primary keys, foreign keys, nullable relationships and one-to-many cardinalities. Generate bridge tables only after both referenced tables exist. For cycles, use a staged insert or a nullable reference followed by an update.

Example request

Customers → orders → order_items. Each order belongs to one customer, each order has 1–5 items, and the order total equals the sum of item cents.

Reconcile dependent amounts

Generate order line amounts in integer cents, aggregate by order ID and derive the order total. Model taxes, discounts and refunds explicitly instead of independently sampling totals.

Run integrity checks

Test duplicate primary keys, orphan foreign keys, nullability and per-order reconciliation. A zero-orphan count is necessary but does not prove the data is realistic.

Common questions

What is an orphan foreign key?

A child key with no matching parent. It is a structural error unless the relationship is explicitly optional.

Try it with your own dataset

Get started, see pricing or use the API.

Review security and privacy when evaluating Ground for your team.

Related guides