CTEC323 Lecture 6: Dan Zingaro Oise/Ut
CTEC323 Lecture 6: Dan Zingaro Oise/Ut
October 9, 2008
Entity-Relationship Model
Entity-relationship model (ERM) is a conceptual model, independent of the type of database It can be used to generate a relational database, hierarchical database, etc. (but well be using it for relational databases, of course.) Entity-relationship diagrams (ERDs) depict entities, attributes and relationships Two notations: Chen and Crows Foot; we have been and will continue using the latter
Types of Attributes
In an ERD, we can underline attributes that are part of a PK Composite attributes can be subdivided to yield additional attributes
Address can be divided into street, city, province, etc.
Simple attributes cannot be subdivided Usually appropriate to change composite attributes into a series of simple attributes Single-valued attribute can have only a single value (e.g. social insurance number) Multivalued attributes can have many values (e.g. people can have more than one phone number)
Multivalued Attributes
Multivalued attributes should not be implemented in the RDBMS There are two things we can do We can Create several new attributes, one for each of the multivalued attributes components
But, for something like phone numbers, how do we know how many to include? There will be many nulls since not all components will be applicable to everyone
Or, we can create a new entity composed of the multivalued attributes components
There is then a 1:M relationship between the original entity and the new one representing the multivalued attribute Bonus: we can add new components without modifying table structure
Derived Attributes
A derived attributes value can be calculated from other attributes and so may not actually be stored in the database e.g. if we store a persons date of birth, we can calculate their age (age is a derived attribute) If we include them, we save CPU processing but must ensure that the data remain current If we leave them out, we save storage space but must write more complicated queries Storing derived attributes also lets us maintain historical data
Existence-Dependence
An entity is existence-dependent if it can exist in the database only when it is associated with another related entity occurrence In implementation terms, an entity is existance-dependent if it has a mandatory foreign key (i.e. it cannot be null) Exercise: consider the professor teaches class relationship. Is class existence-dependent on professor?
Weak relationship
PK of child entity does not contain PK component of the parent entity Indicated in crows foot notation with a dashed relationship line
Strong relationship
PK of child entity contains a PK component of the parent entity
Figure: Weak relationship when class PK is class code; strong when it is course code + class section
Participation
Optional participation means that one entity occurrence does not require a corresponding entity occurrence in a particular relationship Optional relationship between entities is indicated by a circle on the side of the optional entity Existance of optionality indicates that minimum cardinality is 0 for the optional entity Existance of mandatory relationship indicates that the minimum cardinality is 1 for the mandatory entity
Degree
Degree indicates the number of entities associated with a relationship Unary: association maintained within a single entity Binary: association between two dierent entities Recursive relationship: occurs when a relationship exists between occurrences of the same entity set
Comparison of Implementations
First implementation
Results in storing nulls for employees that are not married to another employee in the company Can yield data anomalies (e.g. when two people divorce, and we only update one employees row)
Second implementation
Eliminates nulls associated with employees who are not married to another employee in the company We can still record each marriage twice (and introduce inconsistencies by doing so)
Third implementation
Still must be careful (e.g. must have a unique index on the employee number in the third table) What if we have more than two employees with the same marriage number in the third table?
They are in conict because, for example, when we combine tables for the sake of eciency, we may no longer be following design standards