ER Diagram trực quan hóa database schema trước khi implement — bắt buộc với schema phức tạp để tránh costly refactoring sau.
Thành phần: Entities (bảng, hình chữ nhật), Attributes (columns, hình oval — key attribute gạch chân), Relationships (hình thoi nối entities), Cardinality notation.
Crow's Foot notation phổ biến hơn Chen notation trong practice: ký hiệu trên đường relationship — | (one), O (zero), < hoặc > (many).
Ví dụ đọc Crow's Foot: users ||--o{ orders = một user có không hoặc nhiều orders; orders }|--|{ products = many-to-many với mandatory participation.
Tools: dbdiagram.io (code-based, version control friendly), draw.io, Lucidchart, ERDPlus.
Prisma schema → auto-generate ERD với Prisma Studio.
Bước thiết kế:
- identify entities từ business requirements,
- xác định attributes và PK cho mỗi entity,
- xác định relationships và cardinality,
- resolve M:N thành junction tables,
- review với team trước khi viết DDL