Post on 14-Jan-2016
description
Database Modeling Using the Entity-Relationship Model
(Chapter 3)
Entity-Relationship ModelE-R model was introduced by Peter Chen in 1976It is a graphical approach to database modeling.It describes data as entities, relationships and attributes.
Elements of ER ModelKey elements:EntitiesAttributesRelationshipsIdentifiers
EntitiesAn entity is the basic object that the E-R model represents An entity is something that can be identified in real world.ExamplesPeter Johns, MIS, 12345May Carson, CS, 67890Dee Conway, 1134, CS, Prof.Entities of a given type are grouped into entity classes.
Entities (2)
AttributesEntities have attributes that describe the entitys characteristics.
Types of attributes: single-valued, multi-valued, composite. Example are:Single-value: Year 2Multi-valued: {MIS, Marketing}Composite: (FirstName, LastName)
RelationshipsA relationship indicated how one or more entity classes interact with one and another.Each entity plays a role in a relationship.Degree of the relationship: number of entities in a relationship.Understanding the relationship is important because it will affect how the database is constructed and used.
E-R Conceptsentity type = entity class = entityentity instance = entity occurrence = recordentity type: a set of objects in the real world with the same properties (not the same values) with a physical or conceptual existenceentity instance: each entity has its own values for each attribute
Basic E-R NotationEntityWeak EntityRelationshipIdentifying RelationshipAttributeMultivalued AttributeDerived Attribute
Basic E-R NotationRelationship degreeUnaryBinaryTernary
E-R Model ConstructsStrong versus Weak Entity TypeIndependent versus dependent entityIdentifying ownerIdentifying relationshipWeak entity identifier is its partial identifier combined with that of its owner.
E-R Model ConstructsAttribute - property or characteristic of an entity typeSimple versus Composite AttributeSingle-valued versus Multivalued AttributeStored versus Derived Attributes.
Composite AttributeAddressStreetCityStateZip
Entity with multivalued attribute (Skills) and derived attribute (Years_Employed)
Simple and composite Key attributes(a) Simple key attribute
Simple and composite Key attributes(a) Composite key attribute
Stored vs Derived AttributesDerived attribute: the value of an attribute is derived fromsomething else
Derived AttributesExample 1: Age = today date - DOBExample 2: total number of staff can be calculated by counting the total number of staff entity instances.Example 3: deposit = 2 * rent
How to Interpret this Model
E-R Model ConstructsIdentifier or Key - An attribute (or combination of attributes) that uniquely identifies individual instances of an entity type.Simple Key versus Composite KeyCandidate Key
E-R Model ConstructsCriteria for selecting IdentifiersWill not change valueWill not be nullNo intelligent identifiers (containing e.g. locations or people that might change)Substitute new, simple keys for long, composite key.
RelationshipsDefinition: a meaningful association among entity classes.Meaningful implies that the relationship allows us to answer questions that could not be answered given only the entity classes.In general, any number of entity classes may participate in a relationship.
RelationshipsRelationship type versus InstanceDegree of Relationship - number of entity types that participate in itA relationship is represented by a diamond in the diagram with lines linking to the corresponding entity classes.
Relationship SetThink of the value of relationship set as a tableOne column for each of the connected entity sets.One row for each list of entities, one from each set, which is connected by the relationship.
Professors
Courses
Holmes
COP3337
Barton
COP4610
Milani
COP4010
RelationshipsDegree of RelationshipUnary RelationshipBinary RelationshipTernary RelationshipAttributes of RelationshipMany to Many
Relationships of different degrees(a) Unary relationshipsOne-to-oneIs_married_to11EMPLOYEEManagesN1One-to-many
Role NamesUnary relationship: the same entity class participates more than once in different roles.EMPSupervisesSuperviseeSupervisor1N
(b) Binary relationshipsEMPLOYEEPARKING PLACEAssigned11One-to-onePRODUCT LINEPRODUCTContains1NOne-to-manySTUDENTCOURSERegistersMNMany-to-many
Role NamesRole names may also be used when two entity classes are associated through more than one relationshipsEMPDEPTmanagermemberof staffN111
Multiway relationshipUsually binary relationships (connecting two E.S.) suffice. However, there are some cases where three or more E.S. must be connected by one relationship. Example: relationship among students, courses, TA's.StudentsCoursesTAsMNN1
Multiway relationshipWhat if students are divided into sections, each headed by a TA?A student would be related to only one of the TA's for the course. Which one? Need a 3-way relationship to tell.StudentsCoursesTAs1MN
Attributes on RelationshipsBecause the price jointly depends on beer and bar,it is actually a shorthand for 3-way relationship
Converting multiway to 2-wayAny relationship with more than two E.S. can be converted to a collection binary many-to-one relationships without losing any information.Steps:Create a new connecting entity set.Introduce many-to-one relationships from the connecting entity set to each of the entity sets (or roles) involved.
BarsBeersThePricePricesTheBarTheBeerBBPN1NN11
4-nary RelationshipSOLICITORBUYERFINANCIAL_INSTITUTIONBIDA buyer, advised by a solicitor, and supported by a financialinstitution, places a bid for a property.A simultaneous relationship among four instances.