1.3 Introduction To DBMS-ER Model
1.3 Introduction To DBMS-ER Model
● However, use this simplified model to help you understand conceptual ideas
without getting lost in details of a complex design
● The description that arises from this design phase serves as the basis for
specifying the conceptual structure of the database
Database System Concepts - 6th Edition 7.2 ©Silberschatz, Korth and Sudarshan
Database Design for a University
● The major characteristics of the university
● The University is organized into departments
● Each department is identified by a unique name (dept name), is located
in a particular building, and has a budget
● Each department has a list of courses it offers
● Each course has associated with it a course id, title, dept name, and
credits, and may also have associated prerequisites
● Instructors are identified by their unique ID
● Each instructor has name, associated department (dept name), and
salary
● Students are identified by their unique ID
● Each student has a name, an associated major department (dept name),
and tot cred (total credit hours the student earned thus far)
Database System Concepts - 6th Edition 7.3 ©Silberschatz, Korth and Sudarshan
Database Design for a University
● The university maintains a list of classrooms, specifying the name of the
building, room number, and room capacity
● The university maintains a list of all classes (sections) taught
● Each section is identified by a course id, sec id, year, and semester, and
has associated with it a semester, year, building, room number, and time
slot id (the time slot when the class meets)
● The department has a list of teaching assignments specifying, for each
instructor, the sections the instructor is teaching
● The university has a list of all student course registrations,
specifying, for each student, the courses and the associated sections
that the student has taken (registered for)
Database System Concepts - 6th Edition 7.4 ©Silberschatz, Korth and Sudarshan
Entity-Relationship Model
Entity-relationship Model
Typically used for conceptual database design
Information
System specific database Schema includes file
organization and choice of index structures
Logical DB design
Physical DB design
Database System Concepts - 6th Edition 7.5 ©Silberschatz, Korth and Sudarshan
ER Model
● How to design a database schema
● ER-data model
● Identify entities
● How those entities are related
● Associated set of constraints
● How to transform an E-R design into a set of basic relation schemas and
how to capture constraints
Database System Concepts - 6th Edition 7.6 ©Silberschatz, Korth and Sudarshan
ER-Model
● Developed to facilitate database design by allowing specification of an
enterprise schema that represents the overall logical structure of a database
● Very useful in mapping the meanings and interactions of real-world enterprises
onto a conceptual schema
● Because of this usefulness, many database-design tools draw on concepts
from the ER model
● The ER data model employs three basic concepts:
● Entity sets,
● Relationship sets,
● Attributes
Database System Concepts - 6th Edition 7.7 ©Silberschatz, Korth and Sudarshan
ER-Model
● Diagrammatic representation of a high-level data model
● Instead of representing all data in tables, it distinguishes between basic
objects, called entities, and relationships among these objects
● Often used as a first step in database-schema design
● A database can be modeled as:
● A collection of entities and
● Relationship among entities
Database System Concepts - 6th Edition 7.8 ©Silberschatz, Korth and Sudarshan
ER-Model Entity
● An entity is a “thing” or “object” in the real world that is distinguishable
from all other objects
● Example: specific person, company, event, plant
● Entity has a set of properties, and the values for some set of properties may
uniquely identify an entity
● For example, person in a university is an entity
● Have a person id property whose value uniquely identifies that person
● Value 677-89-9011 for person id would uniquely identify one particular
person in the university
● Another example, courses can be thought of as entities, and course id
uniquely identifies a course entity in the university
Database System Concepts - 6th Edition 7.9 ©Silberschatz, Korth and Sudarshan
ER-Model Entity Set
● A set of entities of the same type that share the same properties, or
attributes
● Entity set instructor: The set of all people who are instructors at a given
university
● Entity set student: The set of all students in the university
● Entity set song: The collection of all songs in a database
● Other Example: set of all persons, companies, trees, holidays
Database System Concepts - 6th Edition 7.10 ©Silberschatz, Korth and Sudarshan
ER-Model Attributes
Database System Concepts - 6th Edition 7.11 ©Silberschatz, Korth and Sudarshan
Entity Sets instructor and student
Database System Concepts - 6th Edition 7.12 ©Silberschatz, Korth and Sudarshan
Relationship Sets
Database System Concepts - 6th Edition 7.13 ©Silberschatz, Korth and Sudarshan
Relationship Set advisor
Database System Concepts - 6th Edition 7.14 ©Silberschatz, Korth and Sudarshan
Relationship Sets (Cont.)
Database System Concepts - 6th Edition 7.15 ©Silberschatz, Korth and Sudarshan
Degree of a Relationship Set
● Binary relationship
● Involve two entity sets (or degree two)
Most relationship sets in a database system are binary
Example: Student registers a course
● Relationships between more than two entity sets are rare
Example: students work on research projects under the guidance of
an instructor
Relationship proj_guide is a ternary relationship between
instructor, student, and project
Database System Concepts - 6th Edition 7.16 ©Silberschatz, Korth and Sudarshan
Mapping Cardinality Constraints
● Express the number of entities to which another entity can be
associated via a relationship set
● Most useful in describing binary relationship sets
● For a binary relationship set the mapping cardinality must be one of the
following types:
● One to one
● One to many
● Many to one
● Many to many
Database System Concepts - 6th Edition 7.17 ©Silberschatz, Korth and Sudarshan
Mapping Cardinalities
One to one
Note: Some elements in A and B may not be mapped to any elements in other set
Example
An instructor is associated with at most one student via advisor
and a student is associated with at most one instructor via advisor
Database System Concepts - 6th Edition 7.18 ©Silberschatz, Korth and Sudarshan
Mapping Cardinalities
One to many
Example
An instructor can advise several students and a student can be advised by only one instructor
Database System Concepts - 6th Edition 7.19 ©Silberschatz, Korth and Sudarshan
Mapping Cardinalities
Many to one
Example
An instructor may advise at most one student,
But a student may have many advisors
Database System Concepts - 6th Edition 7.20 ©Silberschatz, Korth and Sudarshan
Mapping Cardinalities
Many to many
Example
A student can be advised by several instructors (as in the
case of students advised jointly)
Database System Concepts - 6th Edition 7.21 ©Silberschatz, Korth and Sudarshan
Attributes
Database System Concepts - 6th Edition 7.22 ©Silberschatz, Korth and Sudarshan
Attributes
● Attribute types:
● Simple - Example: First_Name, Salary
● Composite
= Simple Attributes
Database System Concepts - 6th Edition 7.23 ©Silberschatz, Korth and Sudarshan
Attribute Types
Database System Concepts - 6th Edition 7.24 ©Silberschatz, Korth and Sudarshan
Keys
● Used to specify how entities within a given entity set are distinguished
● In other words, no two entities in an entity set are allowed to have exactly
the same value for all attributes
● Key are applicable to relation schemas also to identify relationships
uniquely, and thus distinguish relationships from each other
Types:
● Super key
● Candidate key
● Primary key
● Foreign key
Database System Concepts - 6th Edition 7.25 ©Silberschatz, Korth and Sudarshan
Keys
● Super key
● A set of one or more attributes taken collectively whose values
uniquely determine each entity in the entity set
● Example
ID and name of instructor
ID and title of course
Course_ID and title of course
Database System Concepts - 6th Edition 7.26 ©Silberschatz, Korth and Sudarshan
Keys
● Candidate key
● Requires super keys for which no proper subset is a super key
● A minimal super key of an entity set is called candidate key
● Example
ID is candidate key of instructor, Course_ID is candidate key of
course
● Several distinct sets of attributes can also serve as a candidate key
Database System Concepts - 6th Edition 7.27 ©Silberschatz, Korth and Sudarshan
Keys
● Primary key
● Although several candidate keys may exist, one of the candidate keys is
selected to be the Primary Key by the database designer to identify
tuples within a relation
● Must be chosen with care, avoid repeated value attribute
● Select attribute whose values are never, or very rarely, changed
● NOTE: Primary key attributes in entity, relation should be underlined in
the model and listed before the other attributes in schema
● Example:
Instructor ID
In the United States, the social-security number attribute of a person
would be a candidate key
In India, VoterID, PAN ID
Database System Concepts - 6th Edition 7.28 ©Silberschatz, Korth and Sudarshan
Keys
● Foreign key
● An entity, say e1, may include among its attributes the primary key of
another entity, say e2
● This attribute is called a foreign key from e1, referencing e2
● Entity e1 is called “referencing entity” of the foreign key
dependency
● Entity e2 is called “referenced entity” of the foreign key
● Example
Attribute dept name in instructor is a foreign key from instructor,
referencing department, since dept name is the primary key of
department
– In any database instance, given any tuple, say ta, from the instructor
entity, there must be some tuple, say tb, in the department entity such
that the value of the dept name attribute of ta is the same as the value
of the primary key, dept name, of tb
Database System Concepts - 6th Edition 7.29 ©Silberschatz, Korth and Sudarshan
Redundant Attributes
● Suppose we have entity sets
● instructor, with attributes including dept_name
● a relationship inst_dept relating instructor and department
● Attribute dept_name in entity instructor is redundant since there is an explicit
relationship inst_dept which relates instructors to departments
Database System Concepts - 6th Edition 7.30 ©Silberschatz, Korth and Sudarshan
University Schema- Entity Set, Attributes, Primary Key
1. Student
● Student (SID, name, tot cred) A good entity-relationship
2. Instructor design does not contain
● Instructor (IID, name, salary) redundant attributes
3. Department
● Department(dept name, building, budget)
4. Classroom
● Classroom(building, room number, capacity)
5. Course
● Course(cid, title, credits)
6. Section
● Section( cid, sid, semester, year)
7. Time slot
● Timeslot(tid, {(day, start time, end time) })
Database System Concepts - 6th Edition 7.31 ©Silberschatz, Korth and Sudarshan
University Schema- Relationship Sets
1. inst dept: relating instructors with departments
2. stud dept: relating students with departments
3. teaches: relating instructors with sections
4. takes: relating students with sections, with a descriptive attribute
grade
5. course dept: relating courses with departments
6. sec course: relating sections with courses
7. sec class: relating sections with classrooms
8. sec time slot: relating sections with time slots
9. advisor: relating students with instructors
10. prereq: relating courses with prerequisite courses
Database System Concepts - 6th Edition 7.32 ©Silberschatz, Korth and Sudarshan
E-R Diagrams
Database System Concepts - 6th Edition 7.33 ©Silberschatz, Korth and Sudarshan
Entity With Composite, Multivalued and Derived
Attributes
Database System Concepts - 6th Edition 7.34 ©Silberschatz, Korth and Sudarshan
Relationship Sets
Database System Concepts - 6th Edition 7.35 ©Silberschatz, Korth and Sudarshan
Relationship Sets with Attributes
Database System Concepts - 6th Edition 7.36 ©Silberschatz, Korth and Sudarshan
Roles
● The function that an entity plays in a relationship is called that entity’s role
● Almost, entity sets participating in a relationship set are generally distinct
● Roles are implicit and are not usually specified
Database System Concepts - 6th Edition 7.37 ©Silberschatz, Korth and Sudarshan
Roles
● But, if same entity set is used for the relationship i.e. the same entity set
participates in a relationship set more than once, in different roles
● Example, Course has Prerequisite Course
Database System Concepts - 6th Edition 7.38 ©Silberschatz, Korth and Sudarshan
Roles
● For example, consider the entity set course that records information about all
the courses offered in the university
● The first course of a pair takes the role of courseC1, whereas the second
takes the role of prerequisite course C2
● All relationships of prereq are characterized by (C1, C2) pairs; and (C2,
C1) pairs are excluded
● The labels “course_id” and “prereq_id” are called roles
Database System Concepts - 6th Edition 7.39 ©Silberschatz, Korth and Sudarshan
Cardinality Constraints
● Express the number of entities to which another entity can
be associated via a relationship set
● Express cardinality constraints by drawing either
● A directed line (→), signifying “one,” or
Database System Concepts - 6th Edition 7.40 ©Silberschatz, Korth and Sudarshan
One-to-One Relationship
Database System Concepts - 6th Edition 7.41 ©Silberschatz, Korth and Sudarshan
One-to-Many Relationship
Database System Concepts - 6th Edition 7.42 ©Silberschatz, Korth and Sudarshan
Many-to-One Relationships
Database System Concepts - 6th Edition 7.43 ©Silberschatz, Korth and Sudarshan
Many-to-Many Relationship
Database System Concepts - 6th Edition 7.44 ©Silberschatz, Korth and Sudarshan
Exercise
1. Identify the Entity Attributes and Primary Key for
1. Car
2. Player
2. Discover Primary key for the following:
1. Match(TeamA, TeamB, Date, TeamAScore, TeamBScore, RefID)
3. Describe the following Relationship:
Database System Concepts - 6th Edition 7.45 ©Silberschatz, Korth and Sudarshan
Identify the Entity Attributes and Primary Key
● Entity Car
● Colour
● Number of doors
● Convertible
● Registration number
Database System Concepts - 6th Edition 7.46 ©Silberschatz, Korth and Sudarshan
Identify the Primary Key for Entity Attributes:
● Entity:Player
● Name: string, Position: string, Number: integer, injured: boolean, Team:
string
Attribute Unique Reason
Database System Concepts - 6th Edition 7.47 ©Silberschatz, Korth and Sudarshan
Discover Primary keys
2. Discover Primary key for the following:
● Match(TeamA, TeamB, Date, TeamAScore, TeamBScore, RefID)
Match(TeamA, TeamB, Date, TeamAScore, TeamBScore, RefID)
Database System Concepts - 6th Edition 7.48 ©Silberschatz, Korth and Sudarshan
Describe the following Relationships:
Answer :
An animal has one genome
h A genome describes only one animal
a
s
Database System Concepts - 6th Edition 7.49 ©Silberschatz, Korth and Sudarshan
Draw the following relationships:
● A vehicle has many wheels, each wheel has one vehicle
vehicle wheel
Database System Concepts - 6th Edition 7.50 ©Silberschatz, Korth and Sudarshan
Weak Entity Sets
Database System Concepts - 6th Edition 7.51 ©Silberschatz, Korth and Sudarshan
Weak Entity Sets (Cont.)
● Underline the discriminator of a weak entity set with a dashed line
● Put the identifying relationship of a weak entity in a double diamond
● Primary key for section – (course_id, sec_id, semester, year)
Database System Concepts - 6th Edition 7.52 ©Silberschatz, Korth and Sudarshan
Participation of an Entity Set in a Relationship Set
Database System Concepts - 6th Edition 7.53 ©Silberschatz, Korth and Sudarshan
Weak Entity
Database System Concepts - 6th Edition 7.54 ©Silberschatz, Korth and Sudarshan
One of solutions
● Customer
● Strong entity, primary key: Cust_ID
● ContactNos
● Weak Entity, no primary key
● Relation
● CustomerContactNos
Database System Concepts - 6th Edition 7.55 ©Silberschatz, Korth and Sudarshan
E-R Diagram with a Ternary Relationship
Database System Concepts - 6th Edition 7.56 ©Silberschatz, Korth and Sudarshan
Extended ER Features
Database System Concepts - 6th Edition 7.57 ©Silberschatz, Korth and Sudarshan
Extended E-R Features: Specialization
Database System Concepts - 6th Edition 7.58 ©Silberschatz, Korth and Sudarshan
Extended ER Features: Generalization
● A bottom-up design process – combine a number of entity sets that
share the same features into a higher-level entity set
● Specialization and generalization are simple inversions of each other;
they are represented in an E-R diagram in the same way
● The terms specialization and generalization are used interchangeably
Database System Concepts - 6th Edition 7.59 ©Silberschatz, Korth and Sudarshan
Specialization Example
Database System Concepts - 6th Edition 7.60 ©Silberschatz, Korth and Sudarshan
Aggregation
Database System Concepts - 6th Edition 7.61 ©Silberschatz, Korth and Sudarshan
Aggregation (Cont.)
Database System Concepts - 6th Edition 7.62 ©Silberschatz, Korth and Sudarshan
Aggregation (Cont.)
● Without introducing redundancy, the following diagram represents:
● A student is guided by a particular instructor on a particular project
● A student, instructor, project combination may have an associated evaluation
Database System Concepts - 6th Edition 7.63 ©Silberschatz, Korth and Sudarshan
department (dept name,
building, budget)
ER instructor (ID, name, salary) student (ID, name, tot cred)
Diagram
for a
University
Enterprise
course (course id, title, credits)
Database System Concepts - 6th Edition 7.64 ©Silberschatz, Korth and Sudarshan
Reduction to Relational Schemas
Database System Concepts - 6th Edition 7.65 ©Silberschatz, Korth and Sudarshan
Reduction to Relation Schemas
● Entity sets and relationship sets can be expressed uniformly as relation
schemas
● To represent the contents of the database
● A database which conforms to an E-R diagram can be represented by a
collection of schemas
● For each entity set and relationship set there is a unique schema that is
assigned the name of the corresponding entity set or relationship set
● Each schema has a number of columns (generally corresponding to
attributes), which have unique names
Database System Concepts - 6th Edition 7.66 ©Silberschatz, Korth and Sudarshan
Mapping of an ER-Diagram to a Relational
Database
Five rules are defined to govern how relation/tables are
constructed:
– Rule for entity types
– Rule for relationships
– Rule for attributes
– Rule for generalization/specialization hierarchies
– Rule for participation constraint
Database System Concepts - 6th Edition 7.67 ©Silberschatz, Korth and Sudarshan
Rule for Entity Types
Database System Concepts - 6th Edition 7.68 ©Silberschatz, Korth and Sudarshan
Rule for Entity Types
Design Issue: Representing Strong Entity Set (Atomic attributes)
ID nam
● A strong entity set tot_cr
e
ed
A
student
ID name tot_cred
Database System Concepts - 6th Edition 7.69 ©Silberschatz, Korth and Sudarshan
Rule for Entity Types
Design Issue: Representing Weak Entity Set (Atomic attributes)
● Becomes a table that includes a column for the primary key of the identifying
strong entity set ( no need of separate sec_course)
section ( course_id, sec_id, sem, year )
Database System Concepts - 6th Edition 7.70 ©Silberschatz, Korth and Sudarshan
Rule for relationships
Design Issue: Representing Many to Many Relations
Database System Concepts - 6th Edition 7.71 ©Silberschatz, Korth and Sudarshan
Rule for relationships
Design Issue: Representing Many to 1 and 1 to Many Relations
● Many-to-one and one-to-many relationship sets that are total
Participation on the many-side
● Represented by adding an extra attribute to the “many” side,
containing the primary key of the “one” side
● Example: Instead of creating a schema for relationship set
inst_dept, add an attribute dept_name to the schema arising
from entity set instructor
Database System Concepts - 6th Edition 7.72 ©Silberschatz, Korth and Sudarshan
Rule for relationships
Design Issue: Representing 1 to 1 Relations
● For one-to-one relationship sets, either side can be chosen to act as the
“many” side
● That is, extra attribute can be added to either of the tables
corresponding to the two entity sets
Database System Concepts - 6th Edition 7.73 ©Silberschatz, Korth and Sudarshan
Rule for attributes
Design Issue: Entity Sets vs. Attributes (Multi Valued)
● An Example: Employees can have multiple phones
● Ignore multivalued attributes, if possible
(a) (b)
Ph_No no loc
Database System Concepts - 6th Edition 7.74 ©Silberschatz, Korth and Sudarshan
Rule for attributes
Design Issue: Composite Attribute
● Example: Employee phone having std code + no
Address having Flat no, Apt, street, road
Employee
Employee
address
Flatno Apt …..
Flatno Apt
Solution
Composite attributes are flattened out by creating a separate attribute
for each attribute
Example: The entity set has four attributes addr_FlatNo, addr_Aprt,
addr_Street, and addr_road
Database System Concepts - 6th Edition 7.75 ©Silberschatz, Korth and Sudarshan
Rule for Entity/Relationship
Design Issue: Entity Sets vs. Relationship Sets
(a)
(b)
Database System Concepts - 6th Edition 7.76 ©Silberschatz, Korth and Sudarshan
Rule for Specialization
Design Issue: Specialization
● Method 1:
● Form a schema for the higher-level entity
● Form a schema for each lower-level entity set, include primary key of
higher-level entity set and local attributes
schema attributes
person ID, name, street, city
student ID, tot_cred
employee ID, salary
Database System Concepts - 6th Edition 7.77 ©Silberschatz, Korth and Sudarshan
Rule for Specialization
Design Issue: Specialization
● Method 2:
● Form a schema for each entity set with all local and inherited attributes
schema attributes
person ID, name, street, city
student ID, name, street, city, tot_cred
employee ID, name, street, city, salary
● If specialization is total, the schema for the generalized entity set (person) not
required to store information
● Can be defined as a “view” relation containing union of specialization
relations
● But explicit schema may still be needed for foreign key constraints
● Drawback: name, street and city may be stored redundantly for people who
are both students and employees
Database System Concepts - 6th Edition 7.78 ©Silberschatz, Korth and Sudarshan
Rule for Aggregation
Design Issue: Aggregation
● To represent aggregation, create a schema containing
● primary key of the aggregated relationship,
● the primary key of the associated entity set
● any descriptive attributes
Database System Concepts - 6th Edition 7.79 ©Silberschatz, Korth and Sudarshan
Rule for Aggregation
Design Issue: Aggregation
● For example,
eval_for (s_ID, project_id, i_ID, evaluation_id)
Database System Concepts - 6th Edition 7.80 ©Silberschatz, Korth and Sudarshan
E-R Design Decisions
● The use of an attribute or entity set to represent an object.
● Whether a real-world concept is best expressed by an entity set or a
relationship set.
● The use of a ternary relationship versus a pair of binary relationships.
● The use of a strong or weak entity set.
● The use of specialization/generalization – contributes to modularity in the
design.
● The use of aggregation – can treat the aggregate entity set as a single unit
without concern for the details of its internal structure.
Database System Concepts - 6th Edition 7.81 ©Silberschatz, Korth and Sudarshan
Normalization
A large database defined as a single relation may result in data duplication. This repetition of data
may result in:
1. Making relations very large.
2. It isn't easy to maintain and update data as it would involve searching many records in
relation.
3. Wastage and poor utilization of disk space and resources.
4. The likelihood of errors and inconsistencies increases.
To handle these problems, we should analyze and decompose the relations with redundant data
into smaller, simpler, and well-structured relations that are satisfy desirable properties.
Normalization is a process of decomposing the relations into relations with fewer attributes.
Normalization is the process of organizing the data in the database. Normalization is used to
minimize the redundancy from a relation or set of relations. It is also used to eliminate undesirable
characteristics like Insertion, Update, and Deletion Anomalies.
Normalization divides the larger table into smaller and links them using relationships. The normal
form is used to reduce redundancy from the database table.
Database System Concepts - 6th Edition 7.82 ©Silberschatz, Korth and Sudarshan
Normalization
Why do we need Normalization?
The main reason for normalizing the relations is removing these anomalies.
Failure to eliminate anomalies leads to data redundancy and can cause data integrity and other
problems as the database grows.
Deletion Anomaly: The delete anomaly refers to the situation where the deletion of data results in
the unintended loss of some other important data.
Updation Anomaly: The update anomaly is when an update of a single data value requires
multiple rows of data to be updated.
Database System Concepts - 6th Edition 7.83 ©Silberschatz, Korth and Sudarshan
Types of Normal Forms
Normalization works through a series of stages called Normal forms. The normal forms
apply to individual relations. The relation is said to be in particular normal form if it
satisfies constraints.
Database System Concepts - 6th Edition 7.84 ©Silberschatz, Korth and Sudarshan