Model studio
Draw a data model at three levels, change it, and generate the tables for PostgreSQL, Spark SQL with Delta Lake and T-SQL; then run the PostgreSQL version on the estate's data, in your browser.
Exercise: Remove the repeating group
A policy can have any number of named drivers, and a driver can be named on several policies. Each driver is a party, with the name stored once.
- No repeating group: no numbered driver columns.
- A table between policies and parties records each driver on each policy.
- A driver's name is stored only on the party.
Logical: every attribute with its type and keys (PK, FK), independent of any database; a question mark marks an optional attribute.
Edit policies
A policy, with up to three drivers typed in by name.
The generated tables
Checked in CI on a real PostgreSQL 18.3, and run below in PGlite, the same release.
CREATE TABLE parties (
party_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
full_name text NOT NULL,
birth_date date,
CONSTRAINT pk_parties PRIMARY KEY (party_id)
);
COMMENT ON TABLE parties IS 'A person or an organisation, recorded once.';
COMMENT ON COLUMN parties.party_id IS 'Surrogate key';
CREATE TABLE policies (
policy_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
policy_number text NOT NULL,
start_date date NOT NULL,
driver1_name text,
driver2_name text,
driver3_name text,
CONSTRAINT pk_policies PRIMARY KEY (policy_id)
);
COMMENT ON TABLE policies IS 'A policy, with up to three drivers typed in by name.';
COMMENT ON COLUMN policies.policy_id IS 'Surrogate key';
Run it on the data
PostgreSQL starts in this browser when you press Run.
| Table | PGlite | Seed | Same |
|---|
Used in
- Chapter 5 · Conceptual models: the business in boxes
- Chapter 6 · Logical models
- Chapter 7 · Physical models: one logical model, four physical designs
- Chapter 8 · Canonical models for integration
- Chapter 27 · The medallion architecture 2: design choices
- Chapter 39 · Stage 2: Common meaning
Glossary: Conceptual modelLogical modelPhysical modelPrimary keyForeign key