database 2
database 2
Subject
Database system
Topic
ERdiagram,tables,relations,models
Submitted by
Ayesha mehmood
SP24 BCS 024
Submitted to
Sir Qaizar javed
Submission date
5 APRIL 2025
COMSATS UNIVERSITY
Question 1
What is Data Modeling in the context of database systems? Explain why data
modeling is an important process in designing a database. Provside an example
of a scenario where data modeling is used in the real world.
Data Modeling
Data modeling is the process of creating a visual representation of a database
structure to define how data is stored, organized, and interrelated. It involves
defining entities (tables), attributes (columns), and relationships between
entities to ensure data integrity and efficiency
Why is Data Modeling Important in Database Design?
The relationships between these tables ensure that customers can place multiple
orders, each order can have multiple products, and inventory is updated
accordingly.
Question 2
Entity-Relationship (ER) Diagram Create an ER diagram for a Hospital
Management System. The system should include the following entities: •
Patient (PatientID, Name, Age, Address) • Doctor (DoctorID, Name,
Specialization) • Appointment (AppointmentID, PatientID, DoctorID, Date,
Time) Define the relationships: • A Patient can have multiple Appointments
with different Doctors. • A Doctor can attend to multiple Patients.
Relationships
ER Diagram Structure
ER Diagram Representation
Patient (PatientID, Name, Age, Address)
|1
|
|N
Appointment (AppointmentID, PatientID, DoctorID, Date, Time)
|N
|
|1
Doctor (DoctorID, Name, Specialization)
QUESTION 3
Relationships and Cardinality Define the following types of relationships in an
ER diagram: • One-to-One (1:1) • One-to-Many (1:M) • Many-to-Many (M:M)
Provide a real-world example for each type of relationship, and briefly explain
how they are represented in an ER diagram.
scss
CopyEdit
Country (CountryID, Name) ─── (1:1) ─── President
(PresidentID, Name)
scss
CopyEdit
Teacher (TeacherID, Name) ─── (1:M) ─── Student
(StudentID, Name)
scss
CopyEdit
Student (StudentID, Name) ─── (1:M) ───
Enrollment (EnrollmentID, StudentID, CourseID)
─── (M:1) ─── Course (CourseID, Title)
The Enrollment table breaks the M:M relationship into two 1:M relationships.
Question 4
Design a Relational Schema You are designing a Bookstore Management
System. The system needs to store data for the following entities: • Book
(BookID, Title, AuthorID, Genre) • Author (AuthorID, Name, DateOfBirth) •
Customer (CustomerID, Name, Address) • Order (OrderID, CustomerID,
OrderDate) Define the relationships: • A Customer can place multiple Orders. •
An Order can include multiple Books. Create a relational schema to represent
these entities and their relationships. Use primary keys and foreign keys.
The relational schema defines tables with Primary Keys (PK) and Foreign Keys
(FK) to establish relationships between entities.
Book Table
sql
CopyEdit
Book (BookID PRIMARY KEY, Title, AuthorID FOREIGN KEY
REFERENCES Author(AuthorID), Genre)
Author Table
sql
CopyEdit
Author (AuthorID PRIMARY KEY, Name, DateOfBirth)
Customer Table
Stores details of bookstore customers.
sql
CopyEdit
Customer (CustomerID PRIMARY KEY, Name, Address)
Order Table
Stores orders placed by customers. A customer can place multiple orders, but
each order belongs to one customer.
sql
CopyEdit
Order (OrderID PRIMARY KEY, CustomerID FOREIGN KEY
REFERENCES Customer(CustomerID), OrderDate)
Since an order can contain multiple books and a book can be part of multiple
orders, we need an intermediate table (OrderDetails).
sql
CopyEdit
OrderDetails (OrderID FOREIGN KEY REFERENCES
Order(OrderID),
BookID FOREIGN KEY REFERENCES
Book(BookID),
Quantity,
PRIMARY KEY (OrderID, BookID))
scss
CopyEdit
Author (AuthorID PK, Name, DateOfBirth)
Question 5
Define the following terms: • Entity • Attribute • Relationship Provide an
example of each in the context of a School Management System. For example:
• Entity: Student • Attribute: Name, Age • Relationship: A student enrolls in a
course.
1. Entity
2. Attribute