Synthetic Relational Databases: Generating Multi-Table Data That Doesn't Break Foreign Keys
Generating a single synthetic table is a solved problem. Generating a complete relational database schema — with foreign key constraints intact, cross-table statistical dependencies preserved, and realistic entity relationship structures throughout — is an entirely different challenge, and one that most synthetic data tools handle poorly.
The Single-Table Illusion
Most synthetic data generators are designed around the concept of a single table. Fit a model to a table's columns, sample from that model, output a synthetic table. This works well for simple use cases: generating a synthetic customer list, a synthetic product catalogue, a synthetic set of transactions.
But enterprise data systems don't consist of single tables. They consist of schemas: tens or hundreds of related tables, connected by foreign key relationships, with cross-table business logic encoded in their structures. An order management system might have customers, orders, order lines, products, inventory, warehouses, carriers, and invoices — each table related to others through keys, with statistical dependencies that span the schema.
Generating each table independently and joining them produces data that is superficially plausible but structurally broken:
- Order lines that reference order IDs that don't exist in the orders table
- Invoices for customers that have no matching orders
- Inventory records for product IDs that don't exist in the product catalogue
- Realistic-looking individual values but statistically incoherent cross-table relationships
This is not a theoretical concern. It is why synthetic data generated by naive tools consistently fails to pass the basic integrity checks that real enterprise applications apply to their data.
The Referential Integrity Problem
Referential integrity is the property that every foreign key value in a child table has a corresponding primary key value in the parent table. In a real database, this is enforced by the database engine. In synthetic data generation, it must be enforced by the generator.
This sounds simple but has several non-trivial dimensions:
Cardinality Relationships
One-to-many relationships (one customer → many orders) require the generator to produce a realistic distribution of child record counts per parent. Real customer order counts are not uniformly distributed — they follow a highly skewed distribution where most customers have few orders and a small number of high-value customers have many. A synthetic generator must fit and reproduce this cardinality distribution, not assume a fixed ratio.
Cross-Table Conditional Dependencies
Attributes in child tables often depend statistically on attributes in the parent table. A high-value customer (parent attribute) tends to have larger order values (child attribute). A customer in Germany (parent) will have orders in EUR (child) and shipping addresses in German postal code format. A premium product (parent) will appear on order lines with different discount distributions than a commodity product.
Single-table generators cannot model these cross-table conditional dependencies. A relational generator must propagate parent attributes into the conditional distributions governing child attribute generation.
Multi-Path Dependencies
Some tables have multiple foreign keys, each creating a separate dependency path. An invoice is linked to both a customer and an order. The invoice amount must be consistent with the order amount, which in turn must be consistent with the order lines, which reference products with known prices. Generating the invoice independently — even with the correct customer and order IDs — risks generating an invoice amount that is inconsistent with the referenced order.
The Topological Generation Order
The solution is topological generation: traverse the schema's foreign key dependency graph in topological order (parents before children), generating each table conditionally on the already-generated values of its parent tables.
- Build the dependency graph — construct a directed acyclic graph where each edge represents a FK relationship from child to parent table.
- Topological sort — produce a generation order where every parent table is generated before any of its children.
- Generate root tables — generate tables with no foreign keys (reference data, product catalogues, customer master) from their fitted marginal distributions.
- Generate child tables conditionally — for each child table, sample the cardinality distribution to determine how many child records to generate per parent record, then sample child attributes from conditional distributions given parent attribute values.
- Assign primary keys — generate new synthetic primary keys for child records and populate FK columns with the corresponding parent PKs. No real PKs ever appear in the output.
Handling Circular References and Self-Joins
Some schemas contain circular FK references (a table that references itself, or a cycle between multiple tables) which cannot be topologically sorted. Common examples: an employee table where each employee has a manager_id FK pointing back to the employee table; a category hierarchy where each category has a parent_category_id.
These are handled by breaking the cycle: generate the root records first (employees with no manager, root categories), then generate successive levels of the hierarchy using the previously generated IDs as parent references. The maximum depth of the hierarchy must be parameterised to match the real data's distribution.
Use Cases: Where Relational Synthetic Data Is Critical
- ERP and CRM system testing — testing complex business processes requires full schema fidelity; individual table testing misses cross-entity workflow logic
- Data warehouse development — developing and testing ETL pipelines, data models, and analytics queries requires a realistic multi-table dataset that exercises the full transformation logic
- Application development and QA — realistic test data for application testing must pass all application-level integrity checks, which require a consistent relational schema
- ML feature engineering — many ML features are computed by joining across multiple tables; training on features derived from incoherent single-table synthetic data produces unreliable models
For a deep dive on how synthetic JSON Schema generators handle single-table scenarios, see our article on synthetic data generation from JSON Schema.
Frequently Asked Questions
What is referential integrity in synthetic data?
Referential integrity means every foreign key value in a synthetic child table has a valid corresponding primary key in its parent table — the same constraint enforced by real databases. Without it, synthetic data fails basic database constraints and cannot be used in applications that validate FK relationships.
Why do most synthetic data tools fail at multi-table generation?
Most tools are designed around single-table statistical models. They can fit and sample from a single table's joint distribution but have no mechanism for propagating parent table values into child table generation or enforcing cross-table cardinality constraints. The result is tables that look individually plausible but are incoherent when joined.
How is cardinality (one-to-many ratios) handled in relational synthetic data?
Cardinality is modelled as a probability distribution fitted to the observed child record counts per parent in the real schema. Typically Negative Binomial or Poisson distributions are used, with parameters estimated from the real data. Each synthetic parent record then samples its child count from this distribution before child records are generated.
Can synthetic relational data handle schemas with 100+ tables?
Yes, provided the dependency graph can be topologically sorted (or cycles broken explicitly). The topological generation algorithm scales linearly with schema size. The main constraint at large schema scales is the accuracy of the conditional dependency models between parent and child tables, which require sufficient data to fit reliably.
Does synthetic relational data preserve join statistics?
High-quality relational synthetic data preserves the statistical properties of joined views — including join selectivities, aggregation distributions, and cross-table correlation patterns. This is validated by comparing analytic query results (group-by aggregates, join counts, statistical summaries) between real and synthetic schemas.
AllSynthetica's relational generator handles multi-table schemas with full foreign key integrity, cardinality-preserving generation, cross-table conditional dependency modelling, and cycle detection for self-referential hierarchies.

