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: One party, many roles
One person can be a policyholder, a claimant and a driver at once. Store each person's name and birth date once, in a party table of its own, and let policyholders and claimants refer to it.
- A person's full name and birth date are stored in exactly one table.
- That table is a party of its own, not one of the roles.
- Policyholders and claimants each refer to the party.
- Policies still refer to their policyholder, and claims to their policy and claimant.
Logical: every attribute with its type and keys (PK, FK), independent of any database; a question mark marks an optional attribute.
Edit policyholders
A person who holds a policy, with their own copy of the person's details.
The generated tables
Checked in CI on a real PostgreSQL 18.3, and run below in PGlite, the same release.
CREATE TABLE policyholders (
policyholder_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
full_name text NOT NULL,
birth_date date NOT NULL,
email text,
CONSTRAINT pk_policyholders PRIMARY KEY (policyholder_id)
);
COMMENT ON TABLE policyholders IS 'A person who holds a policy, with their own copy of the person''s details.';
COMMENT ON COLUMN policyholders.policyholder_id IS 'Surrogate key';
CREATE TABLE claimants (
claimant_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
full_name text NOT NULL,
birth_date date NOT NULL,
phone text,
CONSTRAINT pk_claimants PRIMARY KEY (claimant_id)
);
COMMENT ON TABLE claimants IS 'A person who makes a claim, with their own copy of the person''s details.';
COMMENT ON COLUMN claimants.claimant_id IS 'Surrogate key';
CREATE TABLE policies (
policy_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
policy_number text NOT NULL,
policyholder_id integer NOT NULL,
start_date date NOT NULL,
CONSTRAINT pk_policies PRIMARY KEY (policy_id),
CONSTRAINT fk_policies_policyholder_id FOREIGN KEY (policyholder_id) REFERENCES policyholders (policyholder_id)
);
COMMENT ON TABLE policies IS 'A policy, held by one policyholder.';
COMMENT ON COLUMN policies.policy_id IS 'Surrogate key';
COMMENT ON COLUMN policies.policyholder_id IS 'the policyholders row';
CREATE TABLE claims (
claim_id integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,
policy_id integer NOT NULL,
claimant_id integer NOT NULL,
loss_date date NOT NULL,
CONSTRAINT pk_claims PRIMARY KEY (claim_id),
CONSTRAINT fk_claims_policy_id FOREIGN KEY (policy_id) REFERENCES policies (policy_id),
CONSTRAINT fk_claims_claimant_id FOREIGN KEY (claimant_id) REFERENCES claimants (claimant_id)
);
COMMENT ON TABLE claims IS 'A claim against a policy, made by a claimant.';
COMMENT ON COLUMN claims.claim_id IS 'Surrogate key';
COMMENT ON COLUMN claims.policy_id IS 'the policies row';
COMMENT ON COLUMN claims.claimant_id IS 'the claimants row';
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