ER Diagram là bản vẽ schema trước khi code — như bản vẽ nhà trước khi xây, giúp tránh phải đập đi sửa lại tốn kém.
Ba thành phần chính:
- Entity (thực thể = bảng): vẽ hình chữ nhật.
- Attribute (thuộc tính = cột): khóa thì gạch chân.
- Relationship (mối quan hệ) kèm cardinality (một/nhiều).
Ký hiệu Crow's Foot (chân quạ) được dùng nhiều hơn Chen: | = một, O = không, </> = nhiều. Đọc ví dụ: users ||--o{ orders nghĩa là một user có 0 hoặc nhiều order.
Công cụ: dbdiagram.io (viết bằng code, hợp version control), draw.io, Lucidchart; Prisma còn auto-sinh ERD.
Quy trình thiết kế:
- tìm các entity từ yêu cầu nghiệp vụ →
- gán thuộc tính + PK cho mỗi entity →
- xác định quan hệ và cardinality →
- tách N-N thành bảng nối →
- review với team trước khi viết DDL
An ER Diagram is a sketch of the schema before you code — like a house blueprint before building, it helps avoid costly tear-down-and-rebuild later.
Three main components:
- Entity (= table): drawn as a rectangle.
- Attribute (= column): the key is underlined.
- Relationship plus its cardinality (one/many).
Crow's Foot notation is used more than Chen: | = one, O = zero, </> = many. Reading an example: users ||--o{ orders means one user has zero or many orders.
Tools: dbdiagram.io (code-based, version-control friendly), draw.io, Lucidchart; Prisma can also auto-generate ERDs.
Design steps:
- find entities from business requirements →
- assign attributes + PK per entity →
- define relationships and cardinality →
- resolve N-N into junction tables →
- review with the team before writing DDL