Relational Mapping [PDF]

... Models of Software. Conceptual to Relational Mapping. 1 ... No two tuples (rows) in a relation can be identical. –

0 downloads 5 Views 343KB Size

Recommend Stories


An Essential Notation for Object-Relational Mapping
Open your mouth only if what you are going to say is more beautiful than the silience. BUDDHA

[PDF] Mapping the enterprise
This being human is a guest house. Every morning is a new arrival. A joy, a depression, a meanness,

PdF Mapping Experiences
Knock, And He'll open the door. Vanish, And He'll make you shine like the sun. Fall, And He'll raise

The Relational Algebra and The Relational Calculus
Stop acting so small. You are the universe in ecstatic motion. Rumi

Relational Listening
This being human is a guest house. Every morning is a new arrival. A joy, a depression, a meanness,

Relational data
The beauty of a living thing is not the atoms that go into it, but the way those atoms are put together.

Relational Algebra
Love only grows by sharing. You can only have more for yourself by giving it away to others. Brian

relational calculus
I cannot do all the good that the world needs, but the world needs all the good that I can do. Jana

relational psychoanalysis
How wonderful it is that nobody need wait a single moment before starting to improve the world. Anne

Idea Transcript


SWEN-220 Mathematical Models of Software

Conceptual to Relational Mapping

1

Relational (Logical) Design • “Logical” design is where a conceptual design is mapped to a relational schema. • Entry = Conceptual ERD (Cheng Notation) • Exit = Well-structured (Normalized ) Relations in Relational Schema (Structure) Notation (RSN) • Resulting relations will closely resemble their physical representation – tables in a relational database (RDB). 2

Relational Model • A relation is a set of attributes with values for each attribute such that: – Each attribute (column) value must be a single value only. – All values for a given attribute (column ) must be of the same data type. – Each attribute (column) name must be unique. – The order of attributes (columns) is insignificant – No two tuples (rows) in a relation can be identical. – The order of the tuples (rows) is insignificant. 3

What is Relational Schema Notation (RSN)? 1. Notation to show logical database structure. 2. "Flattened" linear text vs. diagram. 3. Entities become relations in the RDB: a. Entity attributes carried over (mostly). b. Entity key attributes become primary relation keys

4. Includes additional relations "implied" by the ERD: a. Multi-valued attributes. b. M : N relationships. c. Relationships with attributes.

RSN Notation R( attr1, attr2, attr3, . . ., attrN ) Relation with N attributes.

R( attr1, attr2, attr3, . . ., attrN ) Primary key attribute(s) are underlined.

R( attr1, attr2, attr3, . . ., attrN ) Foreign key attributes are circled. We name the relation & primary key to which each foreign key refers. NOTE: An attribute can be (part of) both the primary and a foreign key.

RSN Notation R( attr1, attr2, attr3, . . ., attrN ) Relation with N attributes.

R( attr1, attr2, attr3, . . ., attrN ) Primary key attribute(s) are underlined.

R( attr1, attr2, attr3, . . ., attrN ) Foreign key attributes are circled. We name the relation & primary key to which each foreign key refers. NOTE: An attribute can be (part of) both the primary and a foreign key.

Example: Players( ssn, firstName, lastName, uniformNumber, team )

RSN Notation R( attr1, attr2, attr3, . . ., attrN ) Relation with N attributes.

R( attr1, attr2, attr3, . . ., attrN ) Primary key attribute(s) are underlined.

R( attr1, attr2, attr3, . . ., attrN ) Foreign key attributes are circled. We name the relation & primary key to which each foreign key refers. NOTE: An attribute can be (part of) both the primary and a foreign key.

Example:

Primary Key

Players( ssn, firstName, lastName, uniformNumber, team )

RSN Notation R( attr1, attr2, attr3, . . ., attrN ) Relation with N attributes.

R( attr1, attr2, attr3, . . ., attrN ) Primary key attribute(s) are underlined.

R( attr1, attr2, attr3, . . ., attrN ) Foreign key attributes are circled. We name the relation & primary key to which each foreign key refers. NOTE: An attribute can be (part of) both the primary and a foreign key.

Example:

Foreign Key

Players( ssn, firstName, lastName, uniformNumber, team )

RSN Notation R( attr1, attr2, attr3, . . ., attrN ) Relation with N attributes.

R( attr1, attr2, attr3, . . ., attrN ) Primary key attribute(s) are underlined.

R( attr1, attr2, attr3, . . ., attrN ) Foreign key attributes are circled. We name the relation & primary key to which each foreign key refers. NOTE: An attribute can be (part of) both the primary and a foreign key.

Example: Players( ssn, firstName, lastName, uniformNumber, team ) *team refers to teamId in the Teams relation

Entity Conversion Rules 1. Create an RSN relation for each entity. 2. Simple attributes are carried over as is to the RSN 3. Derived attributes are not carried over. 4. Composite attributes are removed; only the simple fields of each composite are carried over to RSN. 5. The entity's key attributes define the primary key in RSN. 6. Multi-valued attributes are replaced by a new relation, say M: a. The attributes in M are those of the multi-valued attribute. b. Create a foreign key from M back to entity from which it was extracted. c. The key of M is all of its attributes.

Conceptual to Relational Mapping 1. Transform regular ERD entities to relations. – Attributes map directly – Entity type identifier becomes primary key(s). PlayerID

Name

Player

Player(PlayerID, Name) 11

Conceptual to Relational Mapping 2. Create additional relations for multi-valued attributes. – –

Second relation has the primary keys as the primary key of the first relation plus the multi-valued attribute. Second relation now contains a foreign key of the first’s relation’s primary key. PlayerID

Name

Player Positions

Player( PlayerID, Name) Positions( PlayerID, Pos) PlayerID refers to PlayerID in Player relation 12

Conceptual to Relational Mapping 3. Map One-to-Many (1:M) Relationships – Primary key on the one-side becomes foreign key on the many-side CustID

OrderID 1

Customer

Makes

N

Order Date

Name

Customer( CustID, Name) Order( OrderID, Date, CustID) CustID refers to CustID in Customer relation

13

Conceptual to Relational Mapping 4. Map Many-to-Many (M:N) Relationships – – –

Create a relation to represent the relationship with a descriptive name. Primary keys of new relation are primary keys of each entity participating in relationship. They also become foreign keys. Add relationship attributes to new relation.

StuID

CourseID M

Student StuName

Completes

N

Course CName

Grade

Student( StuID, StuName) Course( CourseID, Cname) Transcript(StuID, CourseID, Grade) StudID refers to StudID in Student relation CourseID refers to CourseID in Course relation

14

Smile Life

When life gives you a hundred reasons to cry, show life that you have a thousand reasons to smile

Get in touch

© Copyright 2015 - 2024 PDFFOX.COM - All rights reserved.