Chapter 5

Chapter 5

Chapter 17 Logical Database Design for the Relational Model Pearson Education 2009 Chapter 17 - Objectives How to derive a set of relations from a conceptual data model. To create relations for the logical data model to represent the entities, relationships, and attributes that have been identified. Pearson Education 2009

2 Build Logical Data Model Pearson Education 2009 3 Conceptual data model for Staff view showing all attributes 4 Pearson Education 2009 Derive relations for logical data model (1) Strong entity types

For each strong entity in the data model, create a relation that includes all the simple attributes of that entity. For composite attributes, include only the constituent simple attributes. (2) Weak entity types For each weak entity in the data model, create a relation that includes all the simple attributes of that entity. A weak entity must include its Partial key and its owner entity type PK as a FK. The combination of the two keys form the PK of the weak entity. Pearson Education 2009 5 Example Employee Partial Key of

Week entity Emp_NO{PK} Name Fname Mname Lname Sex Salary Dep NO Dependent 1..1 Dependents of 0..* Name

Sex Relationship Employee (Emp_NO, Fname,Mname ,Lname, Sex, Salary) Primary Key Emp_NO DEPENDENT (DepNo, EmpNo, Name, Sex, Relationship ) Primary Key DepNo, EmpNo Foreign Key EMpNo refrences Employee (Emp_NO) Pearson Education 2009 6 Derive relations for logical data model (3) One-to-many (1:*) binary relationship types For each 1:* binary relationship, the entity on the one side of the relationship is designated as the parent entity and the entity on the

many side is designated as the child entity. To represent this relationship, post a copy of the Primary Key attribute(s) of parent entity into the relation representing the child entity, to act as a foreign key. OR Entity with many cardinality in relationship is designated as parent entity, and entity with one cardinality is designated as child entity. Pearson Education 2009 7 Example Child entity Employee

Emp_NO{PK} Name Sex Salary Parent entity 1..* Branch Branch_No {PK} Branch Name Allocates 0..1 Employee (Emp_NO, Name, Sex, Salary,BranchNo) Primary Key Emp_NO

Foreign Key BranchNo refrences Branch (Branch_No) Branch (Branch_No, Branch Name) Primary Key Branch_No Pearson Education 2009 8 Derive relations for logical data model (4) One-to-one (1:1) binary relationship types Creating relations to represent a 1:1 relationship is more complex as the cardinality cannot be used to identify the parent and child entities in a relationship. Instead, the participation constraints are used to decide whether it is best to represent the relationship by combining the entities involved into one relation or by creating two relations and posting a copy of the Primary Key from one relation to the other.

Consider the following (a) mandatory participation on both sides of 1:1 relationship; (b) mandatory participation on one side of 1:1 relationship; (c) optional participation on both sides of 1:1 relationship. Pearson Education 2009 9 Derive relations for logical data model (a) Mandatory participation on both sides of 1:1 relationship Combine entities involved into one relation and choose one of the primary keys of original entities to be Primary Key of the new relation, while the other (if one exists) is used as an alternate key. Pearson Education 2009

10 Example Employee SSN{PK} Name Fname Mname Lname Employee Info 1..1 Emp_NO{PK} Sex Salary DOB

has 1..1 Employee (Emp_NO, SSN, Fname,Mname,Lname, Sex, Salary, DOB) Primary Key Emp_NO Alternate key SSN OR Employee (SSN , Emp_NO, Fname,Mname ,Lname, Sex, Salary,DOB) Primary Key SSN Alternate key Emp_NO Pearson Education 2009 11 Derive relations for logical data model

(b) Mandatory participation on one side of a 1:1 relationship Identify parent and child entities using participation constraints. Entity with optional participation in relationship is designated as parent entity, and entity with mandatory participation is designated as child entity. A copy of Primary Key of the parent entity is placed in the relation representing the child entity. If the relationship has one or more attributes, these attributes should follow the posting of the Primary Key to the child relation. Pearson Education 2009 12 Example Employee Parent entity

Emp_NO{PK} Name Sex Salary Child entity 1..1 Sdate Edate Branch Branch_No {PK} Branch Name Manages 0..1

Employee (Emp_NO, Name, Sex, Salary) Primary Key Emp_NO Branch(Branch_No, Branch Name,Emp_NO, Sdate,Edate) Primary Key Branch_No Foreign key Emp_No refrences Employee (Emp_NO) Pearson Education 2009 13 Derive relations for logical data model (c) Optional participation on both sides of a 1:1 relationship In this case, the designation of the parent and child entities is arbitrary unless we can find out more about the relationship that can help a decision to be made one way or the other. Pearson Education 2009

14 Example Parent entity Operation Op_NO{PK} Child entity Child entity 0..1 We have the choice to post a copy of the Primary Key of Operation entity to Surgery_Material entity or vice versa. Parent entity

Surgery_Material SM_No {PK} Statues Uses 0..1 Operation(Op_NO, ) Surgery_Material(SM_No, Statues,Op_NO) Operation(Op_NO, , SM_No) Surgery_Material(SM_No, Statues) Pearson Education 2009 15 Example Parent entity

Employee Emp_NO{PK} Name Sex Salary Child entity 0..1 If we assume the majority of cars but not all , are used by employee and that minority of employee use cars. Therefore: - The care entity is closer to begin mandatory than employee entity. Car Car_No {PK}

Statues Uses 0..1 Employee (Emp_NO, Name, Sex, Salary) Primary Key Emp_NO Car (Car_NO, Statues, Emp_NO) Primary Key Car_NO Pearson Education 2009 16 (5)Recursive relationships Mapping conclusion a) b)

c) One-to-one (1:1) recursive relationships Single relation with two copies for the primary key with different names. One-to-many (1:*) recursive relationships Single relation with two copies for the primary key with different names. Many-to-many (*:*) recursive relationships Tow relations One relation for the entity type. And create a new relation to represent the relationship. The new relation would only have two attributes, both copies of 17 the primary key.

Example a) One-to-one (1:1) recursive relationships Business rule: Each project must contain anther project, no more. This case occurs rarely in real life applications. Contains Main 1..1 Project Sub Pro_No {PK} 1..1 Statues Project(Pro_No,SubPro_No, Statues)

OR Project(Pro_No,MainPro_No, Statues) Pearson Education 2009 18 Example a) One-to-one (1:1) recursive relationships Business rule: Each project may contain anther project, no more. Contains Main 1..1 Project Sub Pro_No {PK} 0..1 Statues

Project(Pro_No,MainPro_No, Statues) Pearson Education 2009 19 Example b) One-to-many (1:*) recursive relationships Has Parts 1..* Item Base

Item No{PK} 1..1 Size Item(Item_No,Base_No, Size) Pearson Education 2009 20 Example c) Many-to-many (*:*) recursive relationships Contains Parts 1..* Item

Base Item No{PK} 1..* Size Item(Item_No, Size) Parts(Item_No, Parts_No ) Pearson Education 2009 21 Derive relations for logical data model (6) Superclass/subclass relationship types Identify superclass entity as parent entity and subclass entity as the child entity. There are various options on how to represent

such a relationship as one or more relations. The selection of the most appropriate option is dependent on a number of factors such as the disjointness and participation constraints on the superclass/subclass relationship, whether the subclasses are involved in distinct relationships, and the number of participants in the superclass/subclass relationship. Pearson Education 2009 22 Guidelines for representation of superclass / subclass relationship Pearson Education 2009 23

Representation of superclass / subclass relationship based on participation and disjointness 24 Pearson Education 2009 Representation of superclass / subclass relationship based on participation and disjointness 25 Pearson Education 2009 Representation of superclass / subclass relationship based on participation and disjointness 26

Pearson Education 2009 Representation of superclass / subclass relationship based on participation and disjointness 27 Pearson Education 2009 Derive relations for logical data model (7) Many-to-many (*:*) binary relationship types Create a relation to represent the relationship and include any attributes that are part of the relationship. We post a copy of the Primary Key attribute(s) of the entities that participate in the relationship into the new relation, to act as foreign keys. These

foreign keys will also form the Primary Key of the new relation, possibly in combination with some of the attributes of the relationship. Pearson Education 2009 28 Example Employee Emp_NO{PK} Name Sex Salary 1..* Hours

Project Proj_No {PK} Project Name Works on 0..* Employee (Emp_NO, Name, Sex, Salary, Branch No) Primary Key Emp_NO Project (Proj_No, ProjectName) Primary Key Proj_No Work-on(EmpNo,ProjNo, hours) Primary Key Emp_NO Proj_No, Pearson Education 2009 29

Derive relations for logical data model (8) Complex relationship types Create a relation to represent the relationship and include any attributes that are part of the relationship. Post a copy of the Primary Key attribute(s) of the entities that participate in the complex relationship into the new relation, to act as foreign keys. Any foreign keys that represent a many relationship (for example, 1..*, 0..*) generally will also form the Primary Key of this new relation, possibly in combination with some of the attributes of the relationship. Pearson Education 2009 30

Example Sdate Edate Business BizNo {PK} Supplier Contracts SupNo {PK} Lawyer LawNo, {PK} Business (BizNo., ) Supplier(SupNo, ..) Lawyer(LawNo,.) Contract(BizNo, SupNo, LawNo, StDate, EDate)

Pearson Education 2009 31 Derive relations for logical data model (9) Multi-valued attributes Create a new relation to represent multi-valued attribute and include Primary Key of entity in new relation, to act as a foreign key. Unless the multi-valued attribute is itself an alternate key of the entity, the Primary Key of the new relation is the combination of the multi-valued attribute and the Primary Key of the entity. Pearson Education 2009 32

Example The Primary Key of new relation: - the multi-valued attribute if itself an alternate key. ( e.g. we sure that there are no duplicated tel_nos for employees ). -OR the combination of the multivalued attribute and the Primary Key of the entity. ( e.g. 2 brothers work in same company). Employee Emp_NO{PK} Name Sex Salary Tel_no [1..*] Employee (Emp_NO, Name, Sex, Salary)

Primary Key Emp_NO Telephone(Tel_no, EmpNo) Primary Key Tel_no OR Telephone(Tel_no, EmpNo) Primary Key Tel_no, EmpNo Pearson Education 2009 33 Summary of how to map entities and relationships to relations Pearson Education 2009 34

Recently Viewed Presentations

  • The Indian Act - WilsonTeacher.ca

    The Indian Act - WilsonTeacher.ca

    except where the limited exemption under Section 87 of the Indian Act applies. Section 87 says that the "personal property of an Indian or a band situated on a reserve" is tax exempt. The Indian Act prevents non-Aboriginal governments from...
  • Bronx Community Health Dashboard: Drug Abuse and Opioids ...

    Bronx Community Health Dashboard: Drug Abuse and Opioids ...

    Pelham Parkway Allerton-Pelham Gardens Soundview-Castle Hill-Clason Point-Harding Park Eastchester-Edenwald-Baychester Woodlawn-Wakefield Spuyten Duyvil-Kingsbridge Co-op City Pelham Bay-Country Club-City Island Schuylerville-Throgs Neck-Edgewater Park North Riverdale-Fieldston-Riverdale 19 18.100000000000001 17.899999999999999 17 ...
  • Electronic Materials and Graphite Intercalation Compounds

    Electronic Materials and Graphite Intercalation Compounds

    Abstract <br>CHE-0642615 <br>Zharov/Utah <br> <br>Professor Zharov and his coworkers in the Department of Chemistry at the University of Utah are establishing a research program exploring the properties and applications of surface modified nano-porous syn
  • PowerPoint 演示文稿

    PowerPoint 演示文稿

    MingdongOu Peng Cui Jian Pei Ziwei ZhangWenwu Zhu. Tsinghua U Tsinghua U Simon Fraser U . Tsinghua. U. Tsinghua U. Asymmetric Transitivity Preserving Graph Embedding
  • Sampling Strategies and Quadrats An introduction (or a

    Sampling Strategies and Quadrats An introduction (or a

    ACFOR Scale: A = Abundant 80% + C = Common 60 - 79%. F = Frequent 40 - 59%. O = Occassional 20 - 39%. R = Rare 0 - 19%. Choose an appropriate category for the area that the...
  • Employing Non-U.S. Citizens

    Employing Non-U.S. Citizens

    The request form is online at our site. There are certain items we'll need to see first in order to make the documents. The J-1 will apply for the visa at the U.S. Embassy using their immigration documents, financial support...
  • Title

    Title

    Congress uses the budget as a tool to help guide the House and the Senate appropriators with their spending decisions by setting a top-line allocation. ... Watch What's at Stake: A CPA's Insights into the Federal Government's Finances.
  • Multicore, parallelism, and multithreading

    Multicore, parallelism, and multithreading

    Amdahl's Law. Potential performance increase on a parallel computing platform is given by Amdahl's law. Large problems are made upof several parallelizable parts and non-parallelizable parts.