zondag 22 november 2026

Data modelling series : Assertions

Introduction

In data modeling, assertions (also known as business rules or structural assertions) are short, unambiguous sentences written in plain language that define the cardinality between two entities. They serve as a direct translation from a diagram (such as an ERD) into clear agreements with the business.
A well-crafted assertion almost always follows a fixed pattern to capture both minimum (optional vs. mandatory) and maximum (one vs. many) cardinality, and is always read in both directions.


The formula


The Standard Formula for an Assertion : 

A/An [Entity A] [MUST / MAY] [relationship verb] [one / one or more] [Entity B].

MUST = Mandatory (Minimum = 1)
MAY = Optional (Minimum = 0)
one = Maximum = 1
one or more = Maximum = N (many)


Some examples


1. One-to-Many (1:N)  The Most Common Relationship

Scenario: An online store with customers and orders.

Direction 1 (Customer → Order): "A Customer may place one or more Orders." 
Optional, because someone can create an account without buying anything right away: 0..N

Direction 2 (Order → Customer): "An Order must be placed by exactly one Customer." 
Mandatory, an orphaned order without a customer cannot exist: 1..1



2. One-to-One (1:1) – Strict Pairing

Scenario: Employees and their company cars.

Direction 1 (Employee → Company Car): "An Employee may drive at most one Company Car." Optional, not everyone has a company car: 0..1

Direction 2 (Company Car → Employee): "A Company Car must be assigned to exactly one Employee." 
Mandatory, this company does not register unused pool cars: 1..1


3. Many-to-Many (M:N) – Mutual Multiplicity

Scenario: Students and courses at a university.

Direction 1 (Student → Course): "A Student must enroll in one or more Courses." 
Mandatory to maintain active enrollment: 1..N

Direction 2 (Course → Student): "A Course may be attended by one or more Students." 
Optional, a newly created course might still have 0 enrollments: 0..N


Assertions are the ultimate stress test for your data model. When a domain expert reads an assertion and says, "No, that's not how it works in reality" (for example: "An order may also be placed by a guest without an account"), you immediately know you need to adjust your data model and database constraints (NOT NULL vs. NULL) before writing a single line of code.



Hennie


Geen opmerkingen:

Een reactie posten