Entity Relationship Diagram
Entity Relationship (ER) diagrams document database structures and the relationships between tables. Mermaid Studio provides full language support for designing and maintaining your data models.
Basic Example
Section titled “Basic Example”erDiagram CUSTOMER ||--o{ ORDER : places ORDER ||--|{ LINE_ITEM : contains PRODUCT ||--o{ LINE_ITEM : "ordered in"
CUSTOMER { int id PK string name string email } ORDER { int id PK date created int customer_id FK }What You Get
Section titled “What You Get”ER diagrams have comprehensive IDE support:
- Syntax highlighting - Distinct colors for entities, attributes, and relationships
- Code completion - Suggestions for relationship types and attribute modifiers
- Refactoring - Rename entities and update all references
- Find usages - See where entities are referenced in relationships
- Code Vision - Inline hints showing relationship counts
- Navigation bar - Quick access to entities in large schemas
- Code folding - Collapse entity definitions
- Formatting - Auto-format your diagram code
- Inspections - Detect undefined entities and invalid relationships
Quick Syntax Reference
Section titled “Quick Syntax Reference”Relationship cardinality:
||- Exactly oneo|- Zero or one}|- One or moreo{- Zero or more
Common patterns:
||--o{- One to many (optional)||--|{- One to many (required)}o--o{- Many to many
Entity attributes:
erDiagram USER { int id PK string email UK int role_id FK string name }Attribute modifiers: PK (primary key), FK (foreign key), UK (unique key)
For the complete syntax reference, see the Mermaid.js ER Diagram documentation.