Presentation 2
Presentation 2
Design Process Modeling Constraints E-R Diagram Design Issues Weak Entity Sets Extended E-R Features
Modeling
A database can be modeled as:
a collection of entities, relationship among entities.
An entity set is a set of entities of the same type that share the same properties.
Example: set of all persons, companies, trees, holidays
Relationship Sets
A relationship is an association among several entities Example: Hayes depositor A-102 customer entity relationship set account entity A relationship set is a mathematical relation among n 2 entities, each taken from entity sets {(e1, e2, en) | e1 E1, e2 E2, , en En}
Example: Suppose employees of a bank may have jobs (responsibilities) at multiple branches, with different jobs at different branches. Then there is a ternary relationship set between entity sets employee, job, and branch
Relationships between more than two entity sets are rare. Most relationships are binary. (More on this later.)
Attributes
An entity is represented by a set of attributes, that is descriptive properties possessed by all members of an entity set. Example: customer = (customer_id, customer_name, customer_street, customer_city ) loan = (loan_number, amount )
Domain the set of permitted values for each attribute Attribute types: Simple and composite attributes. Single-valued and multi-valued attributes Example: multivalued attribute: phone_numbers Derived attributes Can be computed from other attributes Example: age, given date_of_birth
Composite Attributes
Mapping Cardinalities
One to one
One to many
Note: Some elements in A and B may not be mapped to any elements in the other set
Mapping Cardinalities
Many to one
Many to many
Note: Some elements in A and B may not be mapped to any elements in the other set
Keys
A super key of an entity set is a set of one or more attributes whose values uniquely determine each entity. A candidate key of an entity set is a minimal super key
Customer_id is candidate key of customer account_number is candidate key of account
Although several candidate keys may exist, one of the candidate keys is selected to be the primary key.
Must consider the mapping cardinality of the relationship set when deciding what are the candidate keys Need to consider semantics of relationship set in selecting the primary key in case of more than one candidate key
E-R Diagrams
Rectangles represent entity sets. Diamonds represent relationship sets. Lines link attributes to entity sets and entity sets to relationship sets. Ellipses represent attributes
Double ellipses represent multivalued attributes. Dashed ellipses denote derived attributes.
Roles
Entity sets of a relationship need not be distinct The labels manager and worker are called roles; they specify how employee entities interact via the works_for relationship set. Roles are indicated in E-R diagrams by labeling the lines that connect diamonds to rectangles. Role labels are optional, and are used to clarify semantics of the relationship
Cardinality Constraints
We express cardinality constraints by drawing either a directed line (), signifying one, or an undirected line (), signifying many, between the relationship set and the entity set. One-to-one relationship:
A customer is associated with at most one loan via the relationship borrower A loan is associated with at most one customer via borrower
One-To-Many Relationship
In the one-to-many relationship a loan is associated with at most one customer via borrower, a customer is associated with several (including 0) loans via borrower
Many-To-One Relationships
In a many-to-one relationship a loan is associated with several (including 0) customers via borrower, a customer is associated with at most one loan via borrower
Many-To-Many Relationship
A customer is associated with several (possibly 0) loans via borrower A loan is associated with several (possibly 0) customers via borrower
Partial participation: some entities may not participate in any relationship in the
relationship set
Design Issues
Use of entity sets vs. attributes Choice mainly depends on the structure of the enterprise being modeled, and on the semantics associated with the attribute in question. Use of entity sets vs. relationship sets Possible guideline is to designate a relationship set to describe an action that occurs between entities Binary versus n-ary relationship sets Although it is possible to replace any nonbinary (n-ary, for n > 2) relationship set by a number of distinct binary relationship sets, a nary relationship set shows more clearly that several entities participate in a single relationship. Placement of relationship attributes
We can avoid creating an identifying attribute by making E a weak entity set (described shortly) identified by the three relationship sets
That is, the relationship from account to customer is many to one, or equivalently, customer to account is one to many
Example
Consider the entity type DEPENDENT, related to EMPLOYEE, which is used to keep track of the dependents of each employee via a 1:N relationship . The attributes of DEPENDENT are Name (the first name of the dependent), BirthDate, Sex, and Relationship (to the employee). Two dependents of two distinct employees may, by chance, have the same values for Name, BirthDate, Sex, and Relationship, but they are still distinct entities. They are identified as distinct entities only after determining the particular employee entity to which each dependent is related. Each employee entity is said to own the dependent entities that are related to it. A weak entity type normally has a partial key, which is the set of attributes that can uniquely identify weak entities that are related to the same owner entity . In our example, if we assume that no two dependents of the same employee ever have the same first name, the attribute Name of DEPENDENT is the partial key.
Specialization Example
user-defined
Constraint on whether or not entities may belong to more than one lower-level entity set within a single generalization.
Disjoint
an entity can belong to only one lower-level entity set Noted in E-R diagram by writing disjoint next to the ISA triangle
Overlapping
an entity can belong to more than one lower-level entity set
Aggregation
Consider the ternary relationship works_on, which we saw earlier
Aggregation (Cont.)
Relationship sets works_on and manages represent overlapping information
Every manages relationship corresponds to a works_on relationship However, some works_on relationships may not correspond to any manages relationships
So we cant discard the works_on relationship