ER Diagram
What is an ER Diagram?
ER Diagram stands for Entity-Relationship Diagram. It is a visual representation of the data and its relationships in a database.
Why do we use an ER Diagram?
-
To design or model the database structure before creating it.
-
To understand how different entities (things) relate to each other.
-
Helps in planning and communicating the database design clearly.
What does "Draw ER diagram for given problem" mean?
It means:
-
You are given a description of a system or scenario (the "problem").
-
You need to identify the entities, attributes, and relationships from that description.
-
Then draw a diagram showing:
-
Entities as rectangles,
-
Attributes as ovals connected to entities,
-
Relationships as diamonds connecting entities,
-
And lines showing how entities are linked.
-
Example: Simple ER Diagram for a Library System
Problem Statement:
A library has Books and Members. Members can borrow multiple books. Each book has a title and author. Each member has a member ID and name.
Entities:
-
Book
-
Member
Attributes:
-
Book: BookID, Title, Author
-
Member: MemberID, Name
Relationship:
-
Borrow (between Member and Book)
How ER Diagram looks:
[Member]------(Borrow)-------[Book]
|MemberID |BookID
|Name |Title
|Author
-
Rectangles: Member, Book
-
Diamond: Borrow (relationship)
-
Ovals: Attributes like MemberID, Name, Title, Author (usually drawn connected to entity rectangles)
Example : Simple Student-Course ER Diagram
-
Entities: Student, Course
-
Relationship: Enrolls
-
Attributes:
-
Student: StudentID, Name
-
Course: CourseID, Title
-
-
Relationship connects Student and Course
Example : Library System
-
Entities: Book, Member, Librarian
-
Relationships:
-
Member borrows Book
-
Librarian manages Book
-
-
Attributes:
-
Book: ISBN, Title, Author
-
Member: MemberID, Name
-
Librarian: EmployeeID, Name
-
Example : Hospital Management
-
Entities: Patient, Doctor, Appointment
-
Relationships:
-
Patient has Appointment
-
Doctor conducts Appointment
-
-
Attributes:
-
Patient: PatientID, Name, Age
-
Doctor: DoctorID, Name, Specialty
-
Appointment: Date, Time
-
Example : Online Shopping
-
Entities: Customer, Order, Product
-
Relationships:
-
Customer places Order
-
Order contains Product
-
-
Attributes:
-
Customer: CustomerID, Name
-
Order: OrderID, Date
-
Product: ProductID, Name, Price
-
Example : University Database
-
Entities: Student, Professor, Department
-
Relationships:
-
Student registered in Department
-
Professor works in Department
-
-
Attributes:
-
Student: StudentID, Name
-
Professor: ProfID, Name
-
Department: DeptID, Name
-
Example : Airline Booking System
-
Entities: Passenger, Flight, Booking
-
Relationships:
-
Passenger makes Booking
-
Booking is for Flight
-
-
Attributes:
-
Passenger: PassengerID, Name
-
Flight: FlightID, Source, Destination
-
Booking: BookingID, Date
-
Example : Banking System
-
Entities: Account, Customer, Transaction
-
Relationships:
-
Customer owns Account
-
Account has Transaction
-
-
Attributes:
-
Account: AccountNo, Balance
-
Customer: CustomerID, Name
-
Transaction: TransactionID, Amount, Date
-
Example : School Management
-
Entities: Teacher, Class, Student
-
Relationships:
-
Teacher teaches Class
-
Student attends Class
-
-
Attributes:
-
Teacher: TeacherID, Name
-
Class: ClassID, Subject
-
Student: StudentID, Name
-
Example : Movie Database
-
Entities: Movie, Actor, Director
-
Relationships:
-
Actor acts in Movie
-
Director directs Movie
-
-
Attributes:
-
Movie: MovieID, Title, ReleaseYear
-
Actor: ActorID, Name
-
Director: DirectorID, Name
-
Example : Hotel Reservation
-
Entities: Guest, Room, Reservation
-
Relationships:
-
Guest makes Reservation
-
Reservation includes Room
-
-
Attributes:
-
Guest: GuestID, Name
-
Room: RoomNo, Type
-
Reservation: ReservationID, Date
-
Note
ER diagrams help visualize data and how different entities relate to one another. Each example involves identifying entities, their attributes, and the relationships connecting them.
