0% found this document useful (0 votes)
2 views

database 2

The document is an assignment on database systems, covering topics such as data modeling, ER diagrams, relationships, and relational schemas. It includes definitions, importance, and real-world examples of data modeling, as well as the design of a Hospital Management System and a Bookstore Management System. Additionally, it defines key terms like entity, attribute, and relationship with examples from a School Management System.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

database 2

The document is an assignment on database systems, covering topics such as data modeling, ER diagrams, relationships, and relational schemas. It includes definitions, importance, and real-world examples of data modeling, as well as the design of a Hospital Management System and a Bookstore Management System. Additionally, it defines key terms like entity, attribute, and relationship with examples from a School Management System.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Assignment no 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?

 Ensures Data Consistency & Accuracy – Helps maintain data integrity by


defining relationships and constraints.

 Improves Efficiency & Performance – Optimizes data storage and retrieval


processes.

 Facilitates Communication – Provides a clear framework for developers,


analysts, and stakeholders.

 Reduces Redundancy – Prevents data duplication through normalization


techniques.

 Enhances Scalability – Helps in designing databases that can grow with


increasing data needs.

Real-World Example of Data Modeling

Scenario: Online Retail Store


A company like Amazon uses data modeling to manage customer orders,
products, and payments efficiently. The database might include:

 Customers Table (CustomerID, Name, Email, Address)


 Orders Table (OrderID, CustomerID, OrderDate, TotalAmount)
 Products Table (ProductID, Name, Price, Stock)
 Order_Details Table (OrderID, ProductID, Quantity, Subtotal)

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.

Entities and Attributes

1. Patient (PatientID, Name, Age, Address)


2. Doctor (DoctorID, Name, Specialization)
3. Appointment (AppointmentID, PatientID, DoctorID, Date, Time)

Relationships

 A Patient can have multiple Appointments → One-to-Many (1: N)


 A Doctor can attend to multiple Patients through Appointments →
One-to-Many (1: N)

ER Diagram Structure

 Patient and Doctor have a Many-to-Many (M: N) relationship, which


is resolved through the Appointment table.
 The Appointment table acts as a bridge, linking Patient and Doctor.

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.

Types of Relationships in an ER Diagram

1. One-to-One (1:1) Relationship

 Definition: Each entity in Set A is related to at most one entity in Set B,


and vice versa.
 Example: A Country and its President (each country has only one
president, and each president belongs to one country).
 ER Diagram Representation: A single line between entities with 1:1
notation.

scss
CopyEdit
Country (CountryID, Name) ─── (1:1) ─── President
(PresidentID, Name)

One-to-Many (1:M) Relationship

 Definition: A single entity in Set A can be associated with multiple


entities in Set B, but each entity in Set B is related to only one entity in
Set A.
 Example: A Teacher and their Students (one teacher teaches multiple
students, but each student has only one main teacher).
 ER Diagram Representation: A branching line showing 1:M.

scss
CopyEdit
Teacher (TeacherID, Name) ─── (1:M) ─── Student
(StudentID, Name)

Many-to-Many (M:M) Relationship

 Definition: Multiple entities in Set A can be associated with multiple


entities in Set B.
 Example: Students and Courses (a student can enroll in multiple
courses, and each course can have multiple students).
 ER Diagram Representation: Typically resolved using an intermediate
(junction) table.

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

Stores details about books available in the bookstore.

sql
CopyEdit
Book (BookID PRIMARY KEY, Title, AuthorID FOREIGN KEY
REFERENCES Author(AuthorID), Genre)

Author Table

Stores information about book authors.

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)

OrderDetails Table (Junction Table for Many-to-Many Relationship


between Orders and Books)

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))

Relationships & Keys

1. One-to-Many (1:M) Relationship


o A customer can place multiple orders → Order(CustomerID)
is a Foreign Key referencing Customer(CustomerID).
o An author can write multiple books → Book(AuthorID) is a
Foreign Key referencing Author(AuthorID).
2. Many-to-Many (M:M) Relationship
o An order can contain multiple books, and a book can appear in
multiple orders → OrderDetails is a junction table
connecting Order and Book.
Final Schema Representation

scss
CopyEdit
Author (AuthorID PK, Name, DateOfBirth)

Book (BookID PK, Title, AuthorID FK →


Author(AuthorID), Genre)

Customer (CustomerID PK, Name, Address)

Order (OrderID PK, CustomerID FK →


Customer(CustomerID), OrderDate)

OrderDetails (OrderID FK → Order(OrderID),


BookID FK → Book(BookID),
Quantity,
PRIMARY KEY (OrderID, BookID))

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.

Definitions and Examples in the Context of a School Management System

1. Entity

An entity is a real-world object or concept that can be identified and stored in


a database. Entities have attributes that describe them.
✅ Example: Student (A student is an entity in a school management system).

2. Attribute

An attribute is a characteristic or property of an entity that provides


descriptive information about it.
✅ Example: Name, Age, StudentID (These are attributes of the Student
entity)3. Relationship
A relationship defines how two or more entities are related to each other.
✅ Example: A Student enrolls in a Course (This defines a relationship between
the Student and Course entities).

You might also like