ER diagrams: cardinality and identifying relations

ER diagrams: cardinality and identifying relations

puml.online

简介 / Introduction

ER diagrams (Entity-Relationship diagrams) describe entities, attributes, and their connections in a data model. Cardinality expresses the numerical constraint between two entities, while an Identifying Relationship distinguishes strong from weak entities. This post shows both PlantUML and Mermaid syntax with a side-by-side comparison.

PlantUML 版

PlantUML uses symbol pairs like ||--o{ to express cardinality and identifying relations:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
@startuml
entity "Customer" as C {
+customer_id : int <<PK>>
--
name : varchar
}
entity "Order" as O {
+order_id : int <<PK>>
--
customer_id : int <<FK>>
amount : decimal
}
C ||--o{ O : places

entity "OrderItem" as OI {
+order_id : int <<PK, FK>>
+product_id : int <<PK>>
quantity : int
}
O ||--|| OI : contains
@enduml

Mermaid 版

Mermaid uses single-character combinations for cardinality, with double bars || marking identifying relations:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
erDiagram
CUSTOMER ||--o{ ORDER : places
ORDER ||--|| ORDERITEM : contains
CUSTOMER {
int customer_id PK
varchar name
}
ORDER {
int order_id PK
int customer_id FK
decimal amount
}
ORDERITEM {
int order_id PK, FK
int product_id PK
int quantity
}

对比 / Side-by-side

Feature PlantUML Mermaid
Cardinality symbols ||--o{ etc. | + o combos
Identifying relation Double line || Double line ||
Strong/weak entity Distinguishes by line style Distinguishes by relationship type
Relationship label : label after symbols Written between entities

PlantUML’s symbol system is more visual — line style directly conveys cardinality and entity strength. Mermaid’s compact letter combos are quicker to learn and easier to embed in Markdown.

小结 / Wrap-up

ER diagrams are a core tool in database design. Mastering cardinality and identifying relation syntax in both PlantUML and Mermaid lets you switch tools fluidly across documentation contexts. Pick PlantUML for richer visual expressiveness, or Mermaid for fast inline diagrams in Markdown.

  • Title: ER diagrams: cardinality and identifying relations
  • Author: puml.online
  • Created at : 2026-09-15 09:00:00
  • Updated at : 2026-09-29 01:06:38
  • Link: https://puml.online/blog/er-diagram-cardinality-en/
  • License: This work is licensed under CC BY-NC-SA 4.0.
On this page
ER diagrams: cardinality and identifying relations