Entity Relationship Diagram
An entity relationship diagram models the tables in a database and how they relate to one another through keys. Database designers use it before writing schema migrations to avoid costly structural changes later. Tip: mark cardinality clearly on every relationship line to prevent ambiguity.
The prompt behind this diagram
Create an entity relationship diagram for an online retail database. Include entities Customer, Order, OrderItem, Product, Category, and Payment. Customer has a one-to-many relationship with Order; Order has a one-to-many relationship with OrderItem; Product has a one-to-many relationship with OrderItem and belongs to one Category; Order has a one-to-one relationship with Payment. Show primary keys and foreign keys for each entity along with key attributes like customer_id, order_date, price, and quantity.
Paste your own description (or Terraform / docker-compose / SQL schema) into draft1 and get a diagram like this for your exact system.
What this diagram shows
An Entity Relationship Diagram (ERD) represents the structure of a database by showing entities as rectangular boxes, their attributes as property lists, and the relationships between entities as connecting lines with cardinality notation. The flow demonstrates how data tables connect through foreign keys and primary keys, clarifying which entities reference which others and whether those relationships are one-to-one, one-to-many, or many-to-many. This gives you a complete logical view of your data model before or after building the actual database schema.
Key components
- Entity — A rectangular box representing a table or data object (such as Customer, Product, or Order) that stores a collection of related records.
- Attribute — A property or column name listed inside an entity box (such as customer_id, email, or creation_date) that describes what data the entity holds.
- Primary Key — An attribute marked with (PK) that uniquely identifies each record in an entity and serves as the lookup reference for relationships.
- Foreign Key — An attribute marked with (FK) in one entity that points to the primary key of another entity, establishing the connection between tables.
- Relationship Line — A connecting line between two entities showing how they relate, typically annotated with crow's foot notation or cardinality symbols (1, N, or M).
- Cardinality Notation — Symbols at the ends of relationship lines that indicate whether a relationship is one-to-one (1:1), one-to-many (1:N), or many-to-many (N:M).
When to use it
Use an ERD when designing a new relational database, documenting an existing schema for a team, planning data migrations, or validating that your table structure avoids redundancy and supports all required queries. It is essential before any SQL schema creation, useful for communicating data architecture to non-technical stakeholders, and invaluable when multiple developers need to understand how entities interlock. ERDs are also the standard tool for identifying normalisation problems and ensuring referential integrity.
Common mistakes
- Adding too many attributes to entities without distinguishing between core data and derived or calculated fields, making the diagram unreadable and obscuring the core relationships.
- Omitting many-to-many junction tables or bridge entities that resolve complex relationships, leading to incorrect cardinality notation and misrepresenting actual database structure.
- Failing to mark primary keys and foreign keys clearly, making it impossible for developers to understand which attributes enforce relationships or uniqueness constraints.
Adapting it to your system
Start by listing all the main entities your system needs (User, Product, Order, Payment, etc.). For each, write down its primary key and essential attributes. Then map the relationships: which entity refers to which, and is it one-to-many (a customer has many orders) or many-to-many (a product appears in many orders, and an order contains many products)? Junction tables are needed for many-to-many links. Use consistent naming (snake_case for attributes, singular for entity names) and mark every foreign key reference. Draw or generate the ERD, then validate it against your actual use cases to ensure no missing entities or incorrect cardinality.
More templates
System Architecture Diagram
Generate a clear system architecture diagram online and export an editable draw.io file in seconds with AI.
Network Topology Diagram
Draw a network topology diagram instantly with AI and download it as an editable draw.io file for your documentation.
Aktivitätsdiagramm Für Eine Java-Methode Erstellen
Erstellen Sie ein UML-Aktivitätsdiagramm für Java-Methoden mit KI und exportieren Sie es als editierbare draw.io-Datei
Diagram Przypadków Użycia UML
Wygeneruj diagram przypadków użycia UML online za pomocą AI i pobierz edytowalny plik draw.io.
Cloud Architecture Diagram
Create a cloud architecture diagram with AI and export it instantly as an editable draw.io file.
Cloud Infrastructure Diagram
Generate a detailed cloud infrastructure diagram online using AI and export it as an editable draw.io diagram.
Business Process Flowchart With Decision Points
Build a business process flowchart with decision points using AI and download an editable draw.io file.