Entities and attributes
Group the fields needed for a design discussion under the entity that owns them.
Database relationship modeling
Model database entities, keys, and relationships with the Mermaid ER diagram editor above. Use explicit cardinality to show whether related records are required or optional, then export the ERD for a schema review.
Use the customer, order, and line-item example below to inspect both ends of each relationship. Your existing workspace draft takes priority over the example.
An ER diagram helps answer how records relate, which keys identify them, and whether a relationship is optional. It describes the model; it does not connect to or inspect a database.
Group the fields needed for a design discussion under the entity that owns them.
Use relationship endpoints to distinguish exactly one, zero-or-one, one-or-more, and zero-or-more.
Mark PK, FK, and UK so a reviewer can understand identity and references in the model.
Use a verb such as places or contains to explain why the entities are linked.
Choose one part of the schema and verify both ends of every relationship.
Start with erDiagram, list the entities, and add attributes using type name and optional key markers.
Connect entities with endpoint symbols that match requiredness and multiplicity, then label each relationship with a verb.
Compare the preview with your actual schema rules. Export SVG or PNG and keep the source alongside the schema documentation.
Cardinality and identifying relationships answer different questions. A key marker documents a field; it does not automatically create or validate a database constraint.
Mermaid ER diagram syntax reference →|| means exactly one. o| or |o means zero-or-one; }| or |{ means one-or-more; }o or o{ means zero-or-more. The symbol orientation depends on the endpoint.
erDiagram
CUSTOMER ||..o{ ORDER : places
ORDER ||--|{ LINE_ITEM : containsWrite the type first, then the attribute name, then PK, FK, or UK when relevant. An attribute may have multiple key roles, separated by commas.
erDiagram
ORDER {
string id PK
string customer_id FK
date created_at
}Use -- for an identifying relationship and .. for a non-identifying relationship. In this example an order has its own ID and a customer reference.
erDiagram
CUSTOMER ||..o{ ORDER : places
CUSTOMER {
string id PK
}
ORDER {
string id PK
string customer_id FK
}Mermaid can draw a direct many-to-many relationship. For a relational schema, an associative entity is often more useful because it can hold the references and attributes of that relationship.
erDiagram
STUDENT ||--o{ ENROLLMENT : has
COURSE ||--o{ ENROLLMENT : includes
ENROLLMENT {
string student_id PK, FK
string course_id PK, FK
date enrolled_at
}The customer–order–line-item model shows how to read optional orders and required line items while keeping selected key annotations visible.
erDiagram
CUSTOMER ||--o{ ORDER : places
ORDER ||--|{ LINE_ITEM : contains
CUSTOMER {
string id PK
string email UK
}
ORDER {
string id PK
string customer_id FK
date created_at
}
LINE_ITEM {
string order_id FK
string sku
int quantity
}|| means exactly one at that endpoint. o{ means zero-or-more; |{ means one-or-more. Read the other endpoint as well to understand the full relationship.
No. PK, FK, and UK are annotations in the diagram. This editor does not connect to a database, inspect its schema, or check foreign-key values.
You can draw it directly in Mermaid. When documenting a relational schema, consider a join entity with the two references and any relationship attributes, such as an enrollment date.
They distinguish identifying from non-identifying relationships. This is separate from the endpoint symbols that express how many records may participate.
Include columns that explain identity, relationships, or the design being reviewed. Leave unrelated columns out when they make the ERD harder to read.
Use a class diagram for methods, interfaces, inheritance, and software responsibilities. Use an ER diagram for persisted entities, keys, and database cardinality.
Compare ER notations
Compare syntax, relationship notation, database modeling depth, and maintainability for text-based ERDs.
Read the ER diagram comparison →