Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations...

32
Object-Relational Modeling

Transcript of Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations...

Page 1: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Object-Relational Modeling

Page 2: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.
Page 3: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

What Is a Relational Data What Is a Relational Data Model?Model?

Based on the concept of relations (tables of data)

Relationships established by matching primary and foreign keys

Relational DBMSs (RDBMS) are the most commonly used in industry today.

Many DBMS vendors have begun adding object-oriented features, creating an object-relational model.

Page 4: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

What Is a Relation?What Is a Relation?

A named, two-dimensional table with the following properties (Not all tables are relations):– Entry at each row and column has a single

value. – Entries in columns are from the same set of

values (domain range) and correspond to an attribute

– Each row is unique (i.e. has a nonempty primary key) and corresponds to a record that contains data values for a class.

– Column order does not matter.– Row order does not matter.

This is called First Normal Form (1NF)

Page 5: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Example relation: Note uniqueness of rows guaranteed by Emp_ID. Primary keys are underlined

Page 6: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

What Is Normalization?What Is Normalization?

The process of converting complex data structures into well-structured relations

Well-structured relation – a relation that contains a minimum amount of redundancies and allows rows to be inserted, modified, and deleted without introducing errors or inconsistencies

Page 7: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Consequences of Consequences of Relations that Are Not Relations that Are Not Well StructuredWell Structured

Insertion anomaly – adding new rows forces user to create duplicate data

Update anomaly – changes in one row force changes in other rows because of duplication

Deletion anomaly – deleting rows may cause a loss of data that would be needed for other future rows

Data integrity requires well-structured relations.

Page 8: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

The Normal FormsThe Normal Forms

1st NF – all relations are in 1NF (basic) 2nd NF – relations with no partial-key

functional dependencies 3rd NF – relations with no transitive

functional dependencies

Main goal is to achieve 3NF for all relations.

Page 9: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

What Is a Functional What Is a Functional Dependency?Dependency?

The functional dependency of attribute B on attribute A is represented by an arrow A B, and implies that every valid value of attribute A uniquely determines the value of attribute B.

Determinant – the attribute on the left side of the arrow

All primary keys are determinants

Page 10: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Second Normal Form Second Normal Form (2NF)(2NF)

In 1NF and no partial key functional dependencies

If the primary key is a composite key (composed of more than one attribute) it is possible for an attribute to be functionally dependent on only part of the key

Avoid partial dependencies for 2NF

Page 11: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

This table has a composite key (Emp_ID and Course)

Functional dependencies:(A) Emp_ID Name, Dept, Salary (B)(A) Emp_ID, Course Date_Completed (B)

Name, Dept, and Salary all have partial key dependencies, causing duplication of data.

Page 12: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Problem:If you had to edit Margaret Simpson’s department orsalary, you would have to edit 2 records in this table.

Page 13: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Solution:

Break the relation into two separate relations.

1:N relationship linked by Emp_ID

No partial key dependencies

Well structured

Page 14: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Third Normal Form Third Normal Form (3NF)(3NF) In 2NF and no transitive

functional dependencies Given three attributes in a

relation A, B, C, if A B and B C, this forms a transitive functional dependency

Avoid transitive dependencies for 3NF

Page 15: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Here, (A) Customer_ID (B) Salesperson, and (B) Salesperson (C) Region, cause a transitive dependency

Page 16: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Problem:If you had to edit Region for Salesperson Hicks you would have to edit every customer record in table.

Page 17: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Break the relation into two separate relations.

1:N relationship linked by SalesPerson

No transitive dependencies

Well structured

Solution:

Page 18: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Primary and Foreign Primary and Foreign KeysKeys Primary key – one or more attributes that

together form a unique identifier for rows in the relation

Foreign key – an attribute that appears as a non-primary key attribute or as part of a primary key in one relation and as a primary key attribute in another relation

Relationship – rows in one relation are matched with related rows in another relation through foreign keys

Page 19: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Primary Key in SALES1 table isCustomer_ID

Foreign Key isSalespersonbecause it is linkedto the SPERSONtable by the

Primary KeySalesperson

Page 20: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Referential IntegrityReferential Integrity

A rule that states that any foreign key value (on the relation of the many side) MUST match a primary key value in the relation of the one side

No foreign key can contain a value that is not present in a primary key in the other relation

Page 21: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

The value of Salesperson in each row of table SALES1 is limited to only the current values of Salesperson in the SPERSON table.

Page 22: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Object-Relational Data Object-Relational Data ModelModel

An ORDM is a relational data model with object-oriented extensions

Generalization (& Specialization) Multivalued attributes (i.e. phone_number) Aggregation (nested tables and clusters) Object identifiers (not popularly used) Pointers (alternative to linking – but requires new

syntax for writing queries, not popular) Behaviors (incorporate methods in a relation) Richer set of data types (geographic points,

documents, large objects)

Page 23: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Translating Conceptual Data Translating Conceptual Data Model to Object-Relational Model to Object-Relational ModelModel

Translate classes Each class becomes an object relation Identifier of class becomes primary key of object relation Other attributes become nonprimary attributes of relation

Translate relationships Represented using a foreign key.

Normalize object relations Eliminate redundancy (follow 2nd & 3rd Normal form)

Merge object relations Redundant object relations describing the same class must

be merged and renormalized

Page 24: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Relational approach, forces atomic attributes

Object-relational approach, with multivalued attribute

Comparison of techniques for translating multivalued attributes

Page 25: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

When constructing 1:N relationships, the foreign key is added as an attribute to the relation on the N side.

Page 26: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Associative class and M:N relationship

Associative Class

Many to ManyRelationshipUses primary keysof 3 classes(Ternary)

Page 27: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Points for Figure 8.11Points for Figure 8.11

Associative class is translated into a relation whose primary key is a composite of the primary keys of the other two classes.

M:N relationship between Work and Skill is implemented as an extra relation UseSkills, whose primary key is composed of the primary keys of Work and Skill.

Page 28: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Unary Relationship

Recursive 1:N relationship is represented by a foreign key managerID, which matches with the empId primary key of the same relation.

Page 29: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Unary Relationship

Recursive M:N relationship is represented by a separate relation Prerequisite, whose primary key is composed of two primary key values from the Course relation.

Page 30: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Problems in Merging Problems in Merging Object RelationsObject Relations

Synonyms– Two or more attributes have different

names but same meaning– For example: Employee1(EmpID, name)

Employee2(EmpNo, name)Both keys mean the same but are named differently.

– The analyst should select one of the two primary key names or use a third name but get agreement from affected departments

Page 31: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Problems in Merging Problems in Merging Object RelationsObject Relations Homonyms

– A single attribute name has more than one meaning.

– For example: Account1(AccountNo, amount)

Account2(AccountNo, amount)AccountNo stands for Checking Account No in Account1 and Savings Account No in Account2.

– The analyst should select a new attribute name and get agreement from affected departments.

Page 32: Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.

Any Questions?