The document describes the steps to transform an EER diagram into relational database tables. It discusses mapping regular entities, weak entities, binary relationships, associative entities, and unary relationships. Regular entities are mapped to tables, weak entities require an identifying foreign key, binary relationships use foreign keys, associative entities have composite or surrogate keys, and unary relationships add self-referencing foreign keys. The process is described through examples of transforming common EER patterns into relational structures.
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
78 views
Lecture 13
The document describes the steps to transform an EER diagram into relational database tables. It discusses mapping regular entities, weak entities, binary relationships, associative entities, and unary relationships. Regular entities are mapped to tables, weak entities require an identifying foreign key, binary relationships use foreign keys, associative entities have composite or surrogate keys, and unary relationships add self-referencing foreign keys. The process is described through examples of transforming common EER patterns into relational structures.
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36
Chapter 4
Logical Database Design and the Relational Model
TRANSFORMING EER DIAGRAMSINTO RELATIONS • Transforming (or mapping) EER diagrams into relations is a relatively straightforward process with a well-defined set of rules. In fact, many CASE tools can automatically perform many of the conversion steps. However, it is important that you understand the steps in this process for four reasons: • 1. CASE tools often cannot model more complex data relationships such as ternary relationships and supertype/subtype relationships. In these situations, you may have to perform the steps manually. • 2. There are sometimes legitimate alternatives for which you will need to choose a particular solution. • 3. You must be prepared to perform a quality check on the results obtained with a CASE tool. • 4. Understanding the transformation process helps you understand why conceptual data modeling is different from logical data modeling. TRANSFORMING EER DIAGRAMSINTO RELATIONS • 1. Regular entities are entities that have an independent existence and generally represent real-world objects, such as persons and products. Regular entity types are represented by rectangles with a single line. • 2. Weak entities are entities that cannot exist except with an identifying relationship with an owner (regular) entity type. Weak entities are identified by a rectangle with a double line. • 3. Associative entities (also called gerunds) are formed from many- to-many relationships between other entity types. Associative entities are represented by a rectangle with rounded corners. TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 1: Map Regular Entities • Each regular entity type in an E-R diagram is transformed into a relation. The name given to the relation is generally the same as the entity type. • Each simple attribute of the entity type becomes an attribute of the relation. The identifier of the entity type becomes the primary key of the corresponding relation. • Figure 4-8a shows a representation of the CUSTOMER entity type for Pine Valley Furniture Company. The corresponding CUSTOMER relation is shown in graphical form in Figure 4-8b. TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 1: Map Regular Entities TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 1: Map Regular Entities COMPOSITE ATTRIBUTES • When a regular entity type has a composite attribute, only the simple components of the composite attribute are included in the new relation as its attributes. • Figure 4-9 shows a variant of the example in Figure 4-8, where Customer Address is represented as a composite attribute with components Street, City, and State (see Figure 4-9a). This entity is mapped to the CUSTOMER relation, which contains the simple address attributes, as shown in Figure 4-9b. TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 1: Map Regular Entities COMPOSITE ATTRIBUTES TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 1: Map Regular Entities MULTIVALUED ATTRIBUTES • When the regular entity type contains a multivalued attribute, two new relations (rather than one) are created. The first relation contains all of the attributes of the entity type except the multivalued attribute. • The second relation contains two attributes that form the primary key of the second relation. The first of these attributes is the primary key from the first relation, which becomes a foreign key in the second relation. The second is the multivalued attribute. The name of the second relation should capture the meaning of the multivalued attribute. • An example of this procedure is shown in Figure 4-10. This is the EMPLOYEE entity type for Pine Valley Furniture Company. As shown in Figure 4-10a, EMPLOYEE has Skill as a multivalued attribute. Figure 4-10b shows the two relations that are created. The first (called EMPLOYEE) has the primary key EmployeeID. The second relation (called EMPLOYEE SKILL) has the two attributes, EmployeeID and Skill, which form the primary key. TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 1: Map Regular Entities MULTIVALUED ATTRIBUTES TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 2: Map Weak Entities • Recall that a weak entity type does not have an independent existence but exists only through an identifying relationship with another entity type called the owner. • A weak entity type does not have a complete identifier but must have an attribute called partial identifier that permits distinguishing the various occurrences of the weak entity for each owner entity instance. • For each weak entity type, create a new relation and include all of the simple attributes (or simple components of composite attributes) as attributes of this relation. Then include the primary key of the identifying relation as a foreign key attribute in this new relation. TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 2: Map Weak Entities • An example of this process is shown in Figure 4-11. Figure 4-11a shows the weak entity type DEPENDENT and its identifying entity type EMPLOYEE, linked by the identifying relationship Claims. • Figure 4-11b shows the two relations that result from mapping this E-R segment. • An alternative approach is often used to simplify the primary key of the DEPENDENT relation: Create a new attribute (called DependentID), which will be used as a surrogate primary key in Figure 4-11b. SURROGATE PRIMARY KEY • A serial number or other system assigned primary key for a relation. TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 2: Map Weak Entities TRANSFORMING EER DIAGRAMS INTO RELATIONS • Step 3: Map Binary relationships • Map Binary One-to-Many Relationships • For each binary 1:M relationship, first create a relation for each of the two entity types participating in the relationship, using the procedure described in Step 1. • Next, include the primary key attribute (or attributes) of the entity on the one-side of the relationship as a foreign key in the relation that is on the many-side of the relationship. TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 3: Map Binary relationships • MAP BINARY ONE-TO-MANY RELATIONSHIPS TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 3: Map Binary relationships • MAP BINARY MANY-TO-MANY RELATIONSHIPS • Suppose that there is a binary many-to-many (M:N) relationship between two entity types, A and B. For such a relationship, create a new relation, C. • Include as foreign key attributes in C the primary key for each of the two participating entity types. These attributes together become the primary key of C. Any non key attributes that are associated with the M:N relationship are included with the relation C. TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 3: Map Binary relationships • MAP BINARY MANY-TO-MANY RELATIONSHIPS TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 4: Map Associative Entities • The first step is to create three relations: one for each of the two participating entity types and a third for the associative entity. • The relation formed from the associative entity is known as the associative relation. • The second step then depends on whether on the E-R diagram an identifier was assigned to the associative entity. TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 4: Map Associative Entities IDENTIFIER NOT ASSIGNED • If an identifier was not assigned, the default primary key for the associative relation is a composite key that consists of the two primary key attributes from the other two relations. • These attributes are then foreign keys that reference the other two relations. TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 4: Map Associative Entities IDENTIFIER NOT ASSIGNED TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 4: Map Associative Entities IDENTIFIER ASSIGNED • Sometimes a data modeler will assign a single-attribute identifier to the associative entity type on the E-R diagram. • 1. The associative entity type has a natural single-attribute identifier that is familiar to end users. • 2. The default identifier (consisting of the identifiers for each of the participating entity types) may not uniquely identify instances of the associative entity. TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 4: Map Associative Entities IDENTIFIER ASSIGNED • A new (associative) relation is created to represent the associative entity. • However, the primary key for this relation is the identifier assigned on the E-R diagram. • The primary keys for the two participating entity types are then included as foreign keys in the associative relation. • The result of mapping this entity to a set of relations is shown in Figure 4-16b. • The new associative relation is named SHIPMENT. • CustomerID and VendorID are included as foreign keys in this relation, and ShipmentDate and ShipmentAmount are nonkey attributes. TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 4: Map Associative Entities IDENTIFIER ASSIGNED TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 5: Map unary relationship • Unary relationships are also called recursive relationships. • The two most important cases of unary relationships are one-to-many and many-to-many relationships. • UNARY ONE-TO-MANY RELATIONSHIPS • The entity type in the unary relationship is mapped to a relation using the procedure described in Step 1. • Next, a foreign key attribute is added to the same relation; this attribute references the primary key values in the same relation. TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 5: Map unary relationship • UNARY ONE-TO-MANY RELATIONSHIPS • Figure 4-17a shows a unary one-to-many relationship named Manages that associates each employee of an organization with another employee who is his or her manager. • Each employee may have one manager; a given employee may manage zero to many employees. • The EMPLOYEE relation that results from mapping this entity and relationship is shown in Figure 4-17b. • The (recursive) foreign key in the relation is named ManagerID. This attribute has the same domain as the primary key EmployeeID. • Each row of this relation stores the following data for a given employee: EmployeeID, EmployeeName, EmployeeDateOfBirth, and ManagerID. TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 5: Map unary relationship UNARY ONE-TO-MANY RELATIONSHIPS TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 5: Map unary relationship UNARY MANY-TO-MANY RELATIONSHIPS • The primary key of the associative relation consists of two attributes. • These attributes (which need not have the same name) both take their values from the primary key of the other relation. • Any non key attribute of the relationship is included in the associative relation. • An example of mapping a unary M:N relationship is shown in Figure 4-18. • Figure 4-18a shows a bill-of-materials relationship among items that are assembled from other items or components. TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 5: Map unary relationship UNARY MANY-TO-MANY RELATIONSHIPS • The relations that result from mapping this entity and its relationship are shown in Figure 4-18b. • The ITEM relation is mapped directly from the same entity type. • COMPONENT is an associative relation whose primary key consists of two attributes that are arbitrarily named ItemNo and ComponentNo. • The attribute Quantity is a nonkey attribute of this relation that, for a given item, records the quantity of a particular component item used in that item. TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 5: Map unary relationship UNARY MANY-TO-MANY RELATIONSHIPS TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 6: Map ternary (and n-ary) relationships • A ternary relationship is a relationship among three entity types. • To map an associative entity type that links three regular entity types, we create a new associative relation n. • The default primary key of this relation consists of the three primary key attributes for the participating entity types. • An example of mapping a ternary relationship (represented as an associative entity type) is shown in Figure 4-19. • Figure 4-19a is an E-R segment (or view) that represents a patient receiving a treatment from a physician. • The associative entity type PATIENT TREATMENT has the attributes PTreatment Date, PTreatment Time, and PTreatment Results; TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 6: Map ternary (and n-ary) relationships • The result of mapping this view is shown in Figure 4-19b. • The primary key attributes PatientID, PhysicianID, and TreatmentCode become foreign keys in PATIENT TREATMENT. TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 6: Map ternary (and n-ary) relationships TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 7: : Map Supertype/Subtype relationships • 1. Create a separate relation for the supertype and for each of its subtypes. • 2. Assign to the relation created for the supertype the attributes that are common to all members of the supertype, including the primary key. • 3. Assign to the relation for each subtype the primary key of the supertype and only those attributes that are unique to that subtype. • 4. Assign one (or more) attributes of the supertype to function as the subtype discriminator. TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 7: : Map Supertype/Subtype relationships • An example of applying this procedure is shown in Figures 4-20 and 4- 21. • Figure 4-20 shows the supertype EMPLOYEE with subtypes HOURLY EMPLOYEE, SALARIED EMPLOYEE, and CONSULTANT. • The primary key of EMPLOYEE is Employee Number, and the attribute Employee Type is the subtype discriminator TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 7: : Map Supertype/Subtype relationships TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 7: : Map Supertype/Subtype relationships • The result of mapping this diagram to relations using these rules is shown in Figure 4-21. There is one relation for the supertype (EMPLOYEE) and one for each of the three subtypes. • The primary key for each of the four relations is EmployeeNumber. • A prefix is used to distinguish the name of the primary key for each subtype. For example, SEmployeeNumber is the name for the primary key of the relation SALARIED EMPLOYEE. • Each of these attributes is a foreign key that references the supertype primary key, as indicated by the arrows in the diagram. • Each subtype relation contains only those attributes unique to the subtype. TRANSFORMING EER DIAGRAMSINTO RELATIONS • Step 7: : Map Supertype/Subtype relationships