DBMS Unit -1 - Part-2
DBMS Unit -1 - Part-2
Unit -1 Part-2
DATABASE MANAGEMENT
SYSTEMS
By B. Lokesh Joel
Unit-1:
• Database System Applications: ▪ Introduction to Database Design:
• A Historical Perspective, – Database Design and ER Diagrams,
– Key Tool:
• Primarily uses the Entity-Relationship (ER) model or similar high-level data models.
– Purpose:
• Create a simple, user-friendly description of data that aligns with how users and developers perceive it.
• Facilitates collaboration between technical and non-technical stakeholders.
– Outcome:
• Produces an initial design that:
• Matches real-world processes and entities.
• Can be easily translated into a relational database schema.
Steps in Database Design Process
3. Logical Database Design:
– The process of converting the conceptual design into a database schema
supported by the chosen DBMS.
– Steps
1. Select a DBMS:
• Choose a relational DBMS (RDBMS) for implementation.
2. Convert ER Schema:
• Transform the Entity-Relationship (ER) schema into a relational schema.
3. Result:
• Produce a logical schema, which defines the database structure in the relational
model.
Steps in Database Design Process
4. Schema Refinement
– Purpose:
• Analyze the relational schema to identify and fix potential
problems.
• Refine relations for better organization and efficiency.
– Method:
• Guided by normalization theory:
• Restructure relations to eliminate redundancy and ensure
consistency.
Steps in Database Design Process
5. Physical Database Design:
– Purpose:
• Optimize database design to handle expected workloads efficiently.
– Key Tasks:
• Build indexes to speed up queries.
• Cluster tables to improve performance.
• Perform a substantial redesign of the schema, if necessary.
– Focus:
• Ensure the design meets performance criteria and supports database
tuning.
Steps in Database Design Process
6. Security Design:
– Purpose:
• Address broader aspects of the application beyond the database itself.
– Steps:
1. Identify Entities:
• Users, user groups, departments, and their roles.
2. Define Workflows:
• Outline tasks and processes that involve database interactions.
3. Access Control:
• Determine parts of the database each role can access or restrict.
4. Enforce Security:
• Use DBMS mechanisms to implement and enforce access rules.
– Tools:
• UML (Unified Modeling Language) can assist in designing workflows and security.
Entity-Relationship (ER) Model
Concept Definition Example
Entity Real-world object with attributes. Student, Course, Professor
Attributes Properties describing an entity. StudentID, Name, Age for Student
Relationships Association between entities. Enrolls (Student Course)
Primary Key Unique attribute to identify an entity. StudentID (for Student entity)
Rectangle
Entity Set Rectangle Student
Oval (underlined)
StudentID
Primary Key Underlined Attribute
(Primary Key of Student)
Student_Id
Enrolls
Relationship Diamond Diamond (between Student and
Course)
Representation in ER Model: Student Example
Component Representation Symbol Example
M:N
Cardinality Numbers/Notations 1:N, M:N
(Student enrolls in Courses)
Guardian
Weak Entity Set Double Rectangle Double Rectangle
(related to Student)
GuardianOf
Weak Entity Relationship Double Diamond Double Diamond
(relation for Guardian)
Age
Derived Attribute Dashed Oval Dashed Oval
(calculated from DOB)
– Details:
• Attributes are chosen based on the level of detail required.
• Each attribute is associated with a domain (possible set of values).
– Example:
• name: 20-character strings.
• rating: Integers between 1 and 10.
Entities, Attributes, and Entity Sets
4. Keys
– A key is a minimal set of attributes that uniquely identifies an entity in an
entity set.
– Key Points:
• There can be multiple candidate keys; one is designated as the primary key.
– Example:
• For Employees:
• Attributes: ssn (Primary Key), name, lot.
https://www.geeksforgeeks.org/introduction-of-er-model/
https://www.simplilearn.com/tutorials/sql-tutorial/er-diagram-in-dbms
Types of Attributes
Types of Attributes
▪ There are different types of attributes as discussed below-
1. Simple Attribute 6. Complex Attribute
2. Composite Attribute 7. Stored Attribute
3. Single-Valued Attribute 8. Key Attribute
4. Multi-Valued Attribute 9. Null Attribute
5. Derived Attribute 10. Descriptive Attribute
Types of Attributes
▪ Simple Attribute:
– Attributes that cannot be divided further.
– Example: Name = {Parth}, Age = {23}.
Types of Attributes
▪ Composite Attribute:
– Attributes composed of multiple simple attributes.
– Example: Name (First Name, Last Name), Address (Street, City, Zip Code).
– Here, the attributes “Name” and “Address” are composite attributes as they are composed
of many other simple attributes.
Types of Attributes
▪ Single-Valued Attribute:
– Attributes that can take only one value for a given entity.
– Example: A student's Roll Number or Date of Birth.
– Here, all the attributes are single valued attributes as they can take only one
specific value for each entity
Types of Attributes
▪ Multi-Valued Attribute:
– Attributes that can take more than one value for a given entity.
– Example: Mobile numbers, Email addresses.
– Here, the attributes “Mob_no” and “Email_id” are multi valued attributes as
they can take more than one values for a given entity.
Types of Attributes
▪ Derived Attribute:
– Attributes that are derived from other attributes.
– Example: Age derived from Date of Birth (DOB).
– Here, the attribute “Age” is a derived attribute as it can be derived from the
attribute “DOB”.
Types of Attributes
▪ Complex Attribute:
– Attributes that are a combination of simple, composite, and multivalued
attributes.
– Example: A "Contact Information" attribute that includes phone numbers
(multivalued), email (simple), and address (composite).
Types of Attributes
▪ Stored Attribute:
– Attributes that are physically stored in the database.
– Example: Date of Birth stored in the database, from which Age (a derived
attribute) can be calculated.
Types of Attributes
▪ Key Attribute:
– Attributes that uniquely identify an entity in an entity set.
– Example: Roll Number of a student.
– Here, the attribute “Roll_no” is a key attribute as it can identify any student
uniquely.
Types of Attributes
▪ Null Attribute:
– Attributes that may not have a value for certain entities.
– Example: "Middle Name" attribute for a student may be null if the student does
not have a middle name.
– If a person do not have phone number then a null value is entered in that column.
Types of Attributes
▪ Descriptive Attribute:
– Attributes that provide additional information about relationships.
– Example: In a "Works_In" relationship between Employee and Department,
"Since" is a descriptive attribute showing when the employee started working.
Relationships and Relationship Sets
▪ Definition of Relationships
– A relationship is an association between two or more entities.
▪ Example:
– An employee works in a department.
• The Works_In relationship links Employees and Departments.
– A student enrolls in a course.
– Teacher Teaches Student
Relationships and Relationship Sets
Relationships and Relationship Sets
▪ Relationship Set
– A relationship set is a collection of similar relationships.
▪ Example:
– The Works_In relationship set includes multiple employee-department relationships.
– The Enrolls relationship set includes multiple student-course relationships.
Relationships and Relationship Sets
▪ Mathematically, it is represented as a set of n-tuples:
▪ Example:
– The Works_In relationship set associates employees with departments.
– Each relationship in Works_In tells which employee works in which
department.
Representation in ER Diagram
▪ Entities are shown as rectangles.
▪ Attributes (like name, ID, salary)
are shown as ovals.
▪ Relationships are shown as
diamonds, connecting the • Entities: Employees, Departments
• Relationship: Works_In
entities. • Attributes:
• ssn (Employee ID)
▪ Lines connect entities and • name (Employee Name)
• lot (Parking Lot)
attributes. • dname (Department Name)
• did (Department ID)
• budget (Department Budget)
• since (Descriptive Attribute - Date when an employee joined)
Descriptive Attributes in Relationships
▪ Descriptive attributes store extra information about a relationship, not
an entity.
▪ Example from Figure:
– The attribute since stores the date when an Employee joined a Department.
– This attribute belongs to the Works_In relationship, not to Employees or
Departments.
Degree of Relationship Sets in ER Model
▪ The number of entities participating in a relationship is called
the degree of the relationship.
Degree of a relationship = Number of entity sets participating in it.
Degree of a relationship = 2
Types of Relationships Based on Number of
Entities Participating
▪ Question:
– Determine the Cardinality Ratio between Student and Course.
– If John is enrolled in 3 courses, Alice in 4 courses, and Bob in 2 courses, calculate the total number of enrollments.
– If each course has an average of 10 students enrolled, estimate the total student-course relationships.
▪ Final Answer:
– The Cardinality Ratio between Employee and Department is 1:M (One-to-Many).
Additional Features of the ER Model
▪ Key Constraints
▪ Participation Constraints
▪ Weak Entities
▪ Class Hierarchies
▪ Aggregation
Participation Constraints
▪ In a Relationship, Participation constraint specifies the existence of an entity when
it is related to another entity in a relationship type.
▪ It is also called minimum cardinality constraint.
▪ This constraint specifies the number of instances of an entity that can participate in
a relationship type.
– There are two types of Participation constraint
1. Total participation
2. Partial participation
Total participation
▪ Every entity in the entity set is required to participate in at least one relationship
instance in the relationship set. This is also known as mandatory participation.
– Representation: Depicted by a double line connecting the entity set to the relationship set in an
ER diagram.
– Example: In a university database, if every student must be enrolled in at least one course, the
"Student" entity set would have a total participation constraint in the "Enrolled in" relationship
set.
Partial participation
▪ Entities in the entity set may or may not participate in the relationship
instances of the relationship set. This is referred to as optional
participation.
– Representation: Illustrated by a single line between the entity set and the
relationship set in an ER diagram.
– Example: if some courses might not have any students enrolled, the "Course"
entity set would exhibit partial participation in the "Enrolled in" relationship
set.
Relationship Between Cardinality and
Participation Constraints:
▪ Minimum Cardinality:
– A minimum cardinality of 0 indicates partial participation.
– A minimum cardinality of 1 signifies total participation.
▪ Maximum Cardinality:
– Specifies the maximum number of entities that can participate in a relationship
set.
Key Constraints
▪ Arrows in an ER diagram can be used to indicate key constraints
(sometimes simply referred to as constraints).
▪ If an entity set E has a key constraint in a relationship set R, each entity in E appears in at most one
relationship in R.
▪ Example: Works_In3 involves Employees, Departments, and
Locations.
– Each employee:
• Works in one department.
• At a single location.
▪ A weak entity can only be uniquely identified using a combination of its attributes and the primary key
of another entity, called the identifying owner.
▪ Attribute Inheritance:
– Attributes of Hourly_Emps include those of Employee plus its own
attributes.
– Hourly_Emps ISA (is a) Employee.
Example
▪ The class Person can be specialized into Student and
Faculty.
– Person is the superclass, and Student and Faculty are
subclasses.
– Both subclasses inherit common attributes from Person but also
have unique attributes.
▪ Attributes:
– Person (Superclass): name, address, date_of_birth.
– Student (Subclass): student_id, major, GPA.
– Faculty (Subclass): faculty_id, department, salary.
Class Hierarchies in ER Models
▪ Class hierarchy can be viewed one of two ways
1. Specialization (Top Down Approach)
2. Generalization (Bottom Up Approach)
Specialization and Generalization:
▪ Specialization (Top-Down Approach):
– Specialization identifies subsets of an entity
that share distinct characteristics.
– It breaks an entity into multiple entities from
higher level (superclass) to lower level
(subclass).
– Example: The class Vehicle can be specialized
into Car, Truck, and Motorcycle.
• Vehicle is the superclass, and Car, Truck,
and Motorcycle are subclasses.
• All subclasses inherit attributes from
Vehicle but also contain unique attributes.
Class Hierarchies in ER Models
▪ Attributes:
– Vehicle (Superclass): make, model, year, engine_type.
– Car (Subclass): number_of_doors, trunk_capacity.
– Truck (Subclass): cargo_capacity, number_of_axles.
– Motorcycle (Subclass): type_of_handlebars, has_sidecar
Specialization and Generalization:
▪ Generalization (Bottom-Up Approach):
▪ Generalization combines multiple entities
with common attributes into a superclass.
▪ It is a bottom-up process where shared
features are identified.
▪ Example: Car, Truck, and Motorcycle can
be generalized into Vehicle.
– Car, Truck, and Motorcycle are subclasses,
while Vehicle is the superclass.
– Vehicle contains the common attributes
shared among the subclasses.
Constraints in ISA Hierarchies:
▪ Constraints in ISA hierarchies define rules for how entities
relate to their subclasses.
▪ There are two primary types of constraints:
1. Overlap Constraints
2. Covering Constraints
Overlap constraints tell us whether
an entity (a thing or person) can
belong to more than one group
Constraints in ISA Hierarchies: (subclass) at the same time.
▪ Overlap Constraints:
– Determine whether an entity can belong to
multiple subclasses.
– Example:
• Contract_Emps OVERLAPS Senior_Emps: An
employee can be both a contract employee and
a senior employee.
• Student OVERLAPS TeachingAssistant: A
person can be both a student and a teaching
assistant.
– Default Behavior: In the absence of an explicit
statement, no overlap is assumed, meaning an
entity can belong to only one subclass.
Constraints in ISA Hierarchies:
▪ Covering Constraints:
– Determine whether all entities in the
superclass must belong to at least one
subclass.
– Example:
• Motorboats AND Cars COVER Motor_Vehicles:
Every motor vehicle must be either a motorboat or a
car.
• Student AND Faculty COVER Person: Every person
must be classified as either a student or a faculty
member.
– Default Behavior: In the absence of an explicit
statement, no covering is assumed, meaning
some entities might not belong to any subclass.
Aggregation
▪ In aggregation, a relationship between two
entities is treated as a single entity.
– This new combined entity can then form
relationships with other entities.
– It helps when we need to describe a situation
where relationships themselves are involved in
other relationships.
Aggregation
▪ Example:
– Imagine we have:
• Center: A coaching center offering different courses.
• Course: The specific courses the center offers.
• Visitor: A person who visits the center to make an inquiry.
– Offers: This is a relationship where the Center offers a Course.
– But now, when a Visitor comes to ask questions, they don’t just ask about the Center or
just the Course—they ask about both together.
– So, we treat the Offers relationship (Center + Course) as one aggregated entity.
– Now, this aggregated entity (Center + Course) forms a new relationship with Visitor (like
Aggregation
▪ Why is Aggregation Useful?
– It allows us to handle complex situations where relationships need to interact with other
entities.
– Instead of creating complicated connections, we simplify things by treating the
relationship as a new, higher-level entity.
▪ Real-Life Example:
– Without Aggregation:
You would need to separately connect the Visitor to both the Center and the Course,
which can get confusing.
– With Aggregation:
You combine Center and Course (through the Offers relationship) into a single entity,
and now the Visitor interacts with that combined information.
Aggregation
Conceptual Design With the ER Model
▪ Developing an ER diagram presents several choices, including the
following:
– Should a concept be modeled as an entity or an attribute?
– Should a concept be modeled as an entity or a relationship?
– What are the relationship sets and their participating entity sets? Should
we use
– binary or ternary relationships?
– Should we use aggregation?
Conceptual Design With the ER Model
▪ Entity versus Attribute
▪ Entity versus Relationship
▪ Binary versus Ternary Relationships
▪ Aggregation versus Ternary Relationships
Entity versus Attribute
▪ While identifying the attributes of an entity set, it is sometimes not clear whether a property
should be modeled as an attribute or as an entity set.
▪ For example, consider adding address information to the Employees entity set or using address as
an attribute.
– Example: If the price of a product depends not only on the product but also on the supplier.
▪ ER Diagram Representation:
– Entities: Product (product_ID), Supplier (supplier_ID), Customer (customer_ID)
– Attribute: price
Binary versus Ternary Relationships
Binary versus Ternary Relationships
• Example: Employee, Policy, and Dependents
• Scenario: An employee can own multiple
policies, and each policy can cover multiple
dependents.
• Employees are associated with Policies via a
Covers relationship.
• Policies also relate to Dependents via the
Covers relationship.
• Challenges:
• A policy cannot be owned jointly
by multiple employees.
• Every policy must be owned by
some employee.
• Dependents are a weak entity,
uniquely identified by combining
pname (dependent name) with
policyid.
Binary versus Ternary Relationships
▪ Issues with Ternary Relationship
– Imposing a key constraint on Policies forces each policy to cover only
one dependent.
– Imposing total participation on Policies requires every policy to have at
least one dependent.
– Best approach: Use two binary relationships instead.
Binary versus Ternary Relationships
• Instead of a single ternary relationship,
two binary relationships are used:
• Purchaser Relationship: Links
Employees to Policies.
• Beneficiary Relationship: Links
Policies to Dependents.
• Advantages:
• Maintains data integrity.
• Ensures every policy is owned by an
employee.
• Accurately models dependents
covered under policies.
Aggregation versus Ternary Relationships
▪ Ternary relationships and aggregation are both used to
model complex associations in Entity-Relationship (ER)
diagrams.
▪ The key difference is how they structure the relationships
when multiple entities are involved.
Aggregation versus Ternary Relationships
▪ The "buys" relationship connects Supplier,
Product, and Customer in a single association.
▪ Entities Involved:
– Supplier: Provides products.
– Customer: Buys products.
– Product: The item being purchased.
▪ Advantages of Aggregation:
– Allows reusing the Supplier-Customer relationship in other
associations.
– Enables adding additional attributes or constraints to the
relationship between Supplier and Customer.
– Makes the ER model more structured and scalable.
• The choice between aggregation and ternary relationships
depends on whether a relationship needs to be related to
another entity or relationship.
• If a relationship itself needs to participate in another
relationship, aggregation is used instead of a ternary
relationship.
• Project Sponsorship
• A project can be sponsored by multiple departments.
• A department can sponsor multiple projects.
• Each sponsorship is monitored by one or more employees.
• Ternary Relationship Approach (Figure 2.20)
• A ternary relationship (Sponsors2) directly relates Projects,
Departments, and Employees. • Aggregation Approach (Figure 2.13)
• Limitation: • The Sponsors relationship (between Projects and Departments) is
• Cannot enforce the constraint that each sponsorship must be aggregated into an entity.
monitored by at most one employee. • The Monitors relationship links Employees to this aggregated entity.
• Advantage:
• Allows tracking constraints, such as the "until" attribute (indicating the
duration of monitoring).
• Ensures proper relationship structure without forcing constraints into a
ternary model.
Unit-2
Part-1 By B. Lokesh Joel
103