Relational DB Schema: ER to Relations

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

A seven-step algorithm to convert the basic ER model constructs entity types, binary relationships, n-ary relationships and ______ into relations.

attributes

For each weak entity type W in the ER schema with owner entity type E, create a ______ R

relation

The EMPLOYEE relation's primary key is ______.

Ssn

The function of Step 1 is the mapping of ______ Entity Types.

<p>Regular</p> Signup and view all the answers

For each binary M:N relationship type R, create a new ______ S to represent R.

<p>relation</p> Signup and view all the answers

Flashcards

ER-to-Relational Mapping Algorithm

A step-by-step process to convert an Entity-Relationship (ER) model into a relational database schema.

Mapping Regular Entity Types

Create a relation (table) that includes all the simple attributes of the entity type.

Mapping Weak Entity Types

Create a relation including all simple attributes of the weak entity, incorporating the primary key of the owner entity as a foreign key.

Mapping Binary 1:1 Relationship Types

Choose one of the relations and include the primary key of the other relation as a foreign key.

Signup and view all the flashcards

Mapping Binary 1:N Relationship Types

Include the primary key of the relation representing the other entity type as a foreign key.

Signup and view all the flashcards

Study Notes

  • A relational DB schema is made from an Entity-Relationship (ER) schema
  • A seven-step algorithm converts the basic ER model into relations
  • Types of relations include strong and weak entity types
  • Binary relationships have various constraints
  • Relations can be n-ary, attributes can be simple, composite, and multivalued

Step 1: Mapping Regular Entity Types

  • For each regular (strong) entity type E in the ER schema, you should create a relation R
  • Relation R includes all the simple attributes of E
  • Only include simple component attributes of a composite attribute
  • Set the key attribute of E as the primary key for R
  • If the chosen key of E is a composite, use its set of simple components
  • Relations EMPLOYEE, DEPARTMENT, and PROJECT correspond to regular entity types EMPLOYEE, DEPARTMENT, and PROJECT in the example
  • Ssn, Dnumber, and Pnumber are primary keys for the relations EMPLOYEE, DEPARTMENT, and PROJECT

Step 2: Mapping Weak Entity Types

  • For each weak entity type W in the ER schema with owner entity type E, create a relation R
  • Relation R should include all simple attributes (or simple components of composite attributes) of W as attributes of R
  • Include as foreign key attributes of R, the primary key attribute(s) of the relation(s) that correspond to the owner
  • The relation DEPENDENT corresponds to the weak entity type DEPENDENT, for example
  • The primary key Ssn of the EMPLOYEE relation corresponds to the owner as a foreign key attribute of DEPENDENT which is renamed as Essn
  • A primary key of the DEPENDENT relation is the combination {Essn, Dependent_name

Step 3: Mapping Binary 1:1 Relationship Types

  • For each binary 1:1 relationship type R in the ER schema, identify the relations S and T that correspond to the entity types participating in R
  • Choose one of the relations (S say), and include the primary key of T as a foreign key in S
  • It is better to choose an entity type with total participation in R in the role of S
  • The primary key of the EMPLOYEE relation is included as foreign key in the DEPARTMENT
  • In the example, the 1:1 relationship type MANAGES is mapped by choosing DEPARTMENT to serve in the role of S, its participation in the MANAGES relationship type is total

Step 4: Mapping Binary 1:N Relationship Types

  • For each regular binary 1:N relationship type R, identify the relation S that represents the participating entity type at the N-side of the relationship type
  • Includes the primary key of the relation T as a foreign key in S
  • The relation T represents the other entity type participating in R
  • The 1:N relationship types WORKS_FOR, CONTROLS, and SUPERVISION can be mapped
  • For WORKS_FOR include the primary key Dnumber of the DEPARTMENT relation as foreign key in the EMPLOYEE relation and call it Dno
  • For SUPERVISION include the primary key of the EMPLOYEE relation as foreign key in the EMPLOYEE relation itself (is recursive) and call it Super_ssn
  • The CONTROLS relationship is mapped to the foreign key attribute Dnum of PROJECT, referencing primary key Dnumber of the DEPARTMENT

Step 5: Mapping Binary M:N Relationship Types

  • For each binary M:N relationship type R, create a new relation S to represent R
  • Include as foreign key attributes in S the primary keys of the relations that represent the participating entity types
  • Their combination forms the primary key of S
  • Also, include any simple attributes of the M:N relationship type as attributes of S
  • An M:N relationship type cannot be represented by a single foreign key attribute in one of the participating relations.
  • A separate relationship relation S must be created due to the M:N cardinality ratio
  • Relationship type WORKS_ON is mapped by creating the relation WORKS_ON
  • The primary keys of the PROJECT and EMPLOYEE relations are included as foreign keys in WORKS_ON, and renamed them as Pno and Essn
  • The primary key is a combination of both of these values
  • Attribute Hours is included in WORKS_ON to represent the Hours attribute of the relationship type

Step 6: Mapping Multivalued Attributes

  • For each multivalued attribute A, a new relation R is created
  • This relation Rincludes an attribute corresponding to A, along with the primary key attribute K
  • The primary key K acts as a foreign key in R
  • The relation represents the entity type or relationship type that possesses A as a multivalued attribute
  • The relation DEPT_LOCATIONS is made
  • The attribute Dlocation is a multivalued attribute because LOCATIONS of DEPARTMENT is one
  • Dnumber (the foreign key) represents the primary key of the DEPARTMENT relation
  • The primary key of DEPT_LOCATIONS is the combination of Dnumber and Dlocation

Step 7: Mapping N-ary Relationship Types

  • For each n-ary relationship type R (n > 2), create a new relation S to represent R
  • Include as foreign key attributes in S the primary keys of the relations that represent the participating entity types
  • Simple attributes of the n-ary relationship type should be included
  • The primary key of S is usually a combination of all the foreign keys that reference the relations representing the participating entity types
  • The relationship type SUPPLY is mapped to the relation SUPPLY
  • SUPPLY's primary key is the combination of the three foreign keys {Sname, Part_no, Proj_name}

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Use Quizgecko on...
Browser
Browser