Loading…
Loading…
Under the erd header, blocks declare entities and their fields, and statements
between them declare relations. The connector is the cardinality, drawn in
crow's-foot notation.
Name [color] { fields }, or id = Name { … } for an explicit id.
The opening { and closing } sit on their own lines, with one field per line
between them.name type key. The type and key are optional; a key is pk or fk.
Field names with spaces use quotes.posts { }) is fine; its fields can be filled in later, or
it can stand as a bare table.The connector carries the cardinality. N:1 is sugar that swaps the ends, so it
reads naturally either direction. A : label adds the verb.
| Connector | Cardinality |
|---|---|
1:1 | one to one |
1:N | one to many |
N:1 | many to one (swaps the ends) |
N:M | many to many |
-> | an unspecified link |
arrows: straight (or curved, elbow) draws every relation one way; without
it the layout picks per relation. Tables rank left to right; direction: down
(or left, up) turns them. Tables size their own text, so font-size: is
ignored here with a warning.
Relations reference entities by name; entity.field references are accepted and
resolve to the entity (the field part is documentation). Unlike graph nodes, a
table must be declared: a relation to an undeclared entity is dropped with a
diagnostic.
The coarse words above can't tell "zero or many" from "one or many". For the full notation, write the crow's-foot glyphs directly: one mark per end, exactly as Mermaid does. Each end is one of:
| End glyph | Meaning |
|---|---|
|| | exactly one |
|o / o| | zero or one |
}| / |{ | one or many |
}o / o{ | zero or many |
Join two ends with -- (identifying, a solid line) or .. (non-identifying, a
dashed line): customers ||--o{ orders is exactly-one to zero-or-many.
For a fuller picture, an e-commerce schema tying customers, orders, line items, and products together.
Looking for classes and methods instead of tables? See UML class diagrams, which share this family but switch to UML boxes and relationship arrows.