Introduction To ER Diagrams: Entity-Relationship Diagram (ERD) Tutorial
Introduction To ER Diagrams: Entity-Relationship Diagram (ERD) Tutorial
R. Balcita
Introduction to ER Diagrams
An Entity-Relationship Diagram (ERD) is a visual representation of a database structure that
depicts entities, attributes, and relationships among data. ERDs are essential in designing
relational databases before implementation.
An entity is a real-world object or concept that stores data. Entities can be:
Example:
� Student
� Course
2. Attributes
Example:
� Student → (Student_ID, Name, DOB, Phone)
3. Relationships
Relationships define the association between entities. They are categorized into:
One-to-One (1:1): Each entity instance is related to at most one instance of another entity.
One-to-Many (1:M): One entity is related to multiple instances of another entity.
Many-to-Many (M:N): Multiple instances of one entity relate to multiple instances of another.
Example:
� Student (1:M) � Enrolled In � Course
4. Keys in ERD
Example:
� Student (Student_ID [PK], Name, DOB)
� Course (Course_ID [PK], Course_Name)
Example of an ERD
Scenario: A Library System
A library has Students who borrow Books. Books belong to different Categories.
ERD Representation
1. Entities:
o � Student (Student_ID, Name, Email)
o � Book (Book_ID, Title, Author, ISBN)
o � Category (Category_ID, Category_Name)
o � Borrow (Transaction_ID, Borrow_Date, Return_Date)
2. Relationships:
o Student (1:M) Borrow (M:1) Book
o Book (M:1) Category
pgsql
CopyEdit
[STUDENT] -----< (BORROW) >----- [BOOK] -----< (CATEGORY)
|PK Student_ID |PK Transaction_ID |PK Book_ID
| Name | Borrow_Date | Title
| Email | Return_Date | Author
Conclusion
An ER Diagram is crucial in designing a structured and efficient database. It helps in identifying
entities, attributes, relationships, and keys to avoid redundancy and improve database
integrity.