Lecture 15 - ER Modelling Flashcards
Design Considerations - ER
- Redundancy: A poor design can lead to repeated information, resulting in data inconsistency across various copies of information.
- Incompleteness: A flawed design may make it difficult or impossible to model certain aspects of the enterprise accurately.
Design Approaches - ER
-
Entity-Relationship (ER) Model:
- Models an enterprise as a collection of entities and relationships.
- Entity: A distinguishable “thing” or “object” in the enterprise, described by a set of attributes.
- Relationship: An association among several entities, represented using ER diagrams.
-
Normalization Theory (Covered in Chapter 7):
- Formalizes what constitutes bad design and provides methods to test for it.
Entity Sets
- Entity: An object that exists and is distinguishable from other objects (e.g., person, company, event).
- Entity Set: A collection of entities of the same type sharing the same properties (e.g., set of all persons).
-
Attributes: Descriptive properties of an entity (e.g.,
instructor = (ID, name, salary)
). - Primary Key: A subset of attributes that uniquely identifies each member of the entity set.
Representing Entity Sets in ER Diagrams
- Rectangles represent entity sets.
- Attributes are listed inside the entity rectangle.
- Primary Key attributes are underlined.
Relationship Sets
-
Relationship: An association among several entities.
- Example: The relationship between a student and an instructor acting as an advisor.
-
Relationship Set: A mathematical relation among entities from different entity sets.
- Example:
(44553, 22222)
in theadvisor
relationship set.
- Example:
Relations Sets - ER Diagram
- Diamonds represent relationship sets.
- Lines between related entities depict relationships.
Attributes in Relationship Sets
-
Attributes can be associated with relationship sets.
- Example: The
advisor
relationship set may have an attributedate
to track when the student started with the advisor.
- Example: The
Roles in Relationship Sets
- Entity sets in a relationship can have specific roles.
- Example: In a course prerequisite relationship,
course_id
andprereq_id
are roles.
- Example: In a course prerequisite relationship,
Degree of Relationship Sets
- Binary Relationships: Involve two entity sets (degree two) and are the most common.
-
Ternary Relationships: Involve three entity sets (rare).
- Example: A relationship between
instructor
,student
, andproject
in a research project setting.
- Example: A relationship between
Complex Attributes
-
Attribute Types:
- Simple vs. Composite Attributes: Composite attributes can be divided into smaller sub-parts.
-
Single-valued vs. Multivalued Attributes: Example of multivalued attribute—
phone_numbers
. -
Derived Attributes: Attributes that can be computed from other attributes (e.g.,
age
fromdate_of_birth
).
- Domain: The set of permitted values for each attribute.
Composite Attributes
- Composite Attributes: Attributes that can be divided into subparts, each of which can be an attribute on its own.
- Example: An address can be divided into street number, street name, and apartment number.
Complex Attributes - ER Diagram
Complex attributes like names (first, middle, last) and addresses (street, city, state) can be represented in an ER diagram by showing their subcomponents.
Mapping Cardinality Constraints
-
Cardinality Constraints: Express how many entities in one set can be associated with entities in another set.
- One-to-One: Each entity in one set is associated with at most one entity in the other set.
- One-to-Many: Each entity in one set can be associated with many entities in the other set.
- Many-to-One: Many entities in one set can be associated with one entity in the other set.
- Many-to-Many: Entities in both sets can be associated with many entities in the other set.
Canrdinality Constraints - ER Diagram
- One-to-One: Represented by a directed line in an ER diagram.
- One-to-Many: Represented by an undirected line in an ER diagram.
-
Many-to-one: in a many-to-one relationship between aninstructorand astudent:
- an instructor is associated with at most one student viaadvisor,
- and a student is associated with several (including 0) instructors via advisor
Total and Partial Participation
- Total Participation: Every entity in the entity set must participate in at least one relationship in the relationship set (indicated by a double line).
- Partial Participation: Some entities in the entity set may not participate in any relationship in the relationship set.
Notation for expressing more complex constraints
-
Minimum and Maximum Cardinality: Expressed as l..h, where l is the minimum and h is the maximum cardinality.
- Example: A student must have one advisor (1..1), and an advisor can have multiple students (0..*).
Primary Key for Entity Sets
- Primary Key: A set of attributes that uniquely identifies each entity in an entity set.
- From database perspective, the differences among them must be expressed in terms of their attributes.
- The values of the attribute must be such that they can uniquely identify the entity.
- No two entities in an entity set are allowed to have exactly the same value for all attributes.
- A key for an entity is a set of attributes that suffice to distinguish entities from each other
Weak Entity Sets
- Weak Entity Set: An entity set that cannot be uniquely identified by its attributes alone and relies on a relationship with another (strong) entity set.
- Strong Entity Set: An entity set that can be uniquely identified by its attributes.
- Identifying Relationship: A relationship that connects a weak entity set to its identifying strong entity set.
- The weak entity set is said to beexistence dependenton the identifying entity set.
Expressing Weak Entity Sets - ER Diagram
-
ER Diagram Notation:
- Weak entity sets are represented by double rectangles, and the identifying relationship is represented by a double diamond.
- We underline the discriminator of a weak entity set with a dashed line.
- Primary key forsection– (course_id, sec_id, semester, year)
Redundant Attributes
-
Redundant Attributes: Attributes that replicate information present in a relationship set and should be removed to avoid redundancy.
- Example: If a student is associated with a department via a relationship, including the department name in the student entity is redundant.
Reduction to Relation Schemas
-
Representing Entity Sets:
-
Strong Entity Set: Reduces to a relational schema with the same attributes as the entity set.
- Example:
student(ID, name, tot_cred)
- Example:
-
Weak Entity Set: Becomes a table that includes a column for the primary key of the identifying strong entity set.
- Example:
section(course_id, sec_id, sem, year)
- Example:
-
Strong Entity Set: Reduces to a relational schema with the same attributes as the entity set.
Representation of Entity Sets with Composite Attributes - RS
-
Composite Attributes: Flattened out by creating separate attributes for each component.
- Example: The composite attribute
name
with componentsfirst_name
andlast_name
results inname_first_name
andname_last_name
. - If there is no ambiguity, prefixes can be omitted.
- Example Schema:
instructor(ID, first_name, middle_initial, last_name, street_number, street_name, apt_number, city, state, zip_code, date_of_birth)
- Example: The composite attribute
Representation of Entity Sets with Multivalued Atrributes - RS
-
Multivalued Attribute: Represented by a separate schema.
- The schema includes attributes for the primary key of the original entity and the multivalued attribute.
- Example: The multivalued attribute
phone_number
ofinstructor
is represented byinst_phone(ID, phone_number)
. - Each value of the multivalued attribute corresponds to a separate tuple in the schema EM.
- For example, aninstructorentity with primary key 22222 and phone numbers 456-7890 and 123-4567 maps to two tuples: (22222, 456-7890) and (22222, 123-4567)
###
Representing Relationship Sets - RS
-
Many-to-Many Relationship Set: Represented as a schema with attributes for the primary keys of the participating entity sets and any descriptive attributes of the relationship set.
- Example: The
advisor
relationship is represented asadvisor(s_id, i_id)
.
- Example: The
Redundancy of Schemas
-
Many-to-One Relationship Sets:
- If total on the many-side, it can be 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 the
inst_dept
relationship set, add adept_name
attribute to theinstructor
schema.
-
One-to-One Relationship Sets:
- Either side can be chosen to act as the “many” side by adding an extra attribute to one of the tables corresponding to the entity sets.
- If participation is partial on the “many” side, adding an extra attribute could result in null values.