logical database design relational model. logical database design logical database design: process...

40
Logical Database Design Relational Model

Upload: harvey-roberts

Post on 31-Dec-2015

239 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Logical Database DesignRelational Model

Page 2: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Logical Database Design

• Logical database design: process of transforming conceptual data model into a logical data model.

• Relational data model is the most commonly used in contemporary applications.

Page 3: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Referential Integrity

When referential integrity is enforced• value of foreign key field must exist in primary

key of primary table, else the foreign key value must be null

• can’t delete a record from the primary table if matching records exist in related table

• can’t change primary key value in the primary key table if that record has related records

Page 4: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Transforming E-R Diagrams to Relational Model -- Entities

• Each regular entity type in an ER diagram is transformed into a relation

• For weak entities, create a new relation, but in addition to the simple attributes, must include primary key of owner relation as a foreign key attribute.

Page 5: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Transforming E-R Diagrams to Relational Model -- Attributes

• Each simple attribute of the entity type becomes an attribute of the relation (the identifying attribute becomes the primary key)

• Only simple component attributes of a composite attribute are included

• When the entity type contains a multivalued attribute, two new relations are created

Page 6: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

General Rule for Mapping Binary One-to_Many

• Create a relation (table) for each entity.

• Have the primary key of the table on the one side appear as a foreign key in the table on the many side.

Page 7: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

ERD: Binary One-Many

CUSTOMER LOAN

ISSUED

Page 8: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Logical Schema: Binary One-Many

Customer_ID Name Address Phone#

CUSTOMER

LOAN

Loan_ID Date Amount Interest_rate Term Type Customer_ID

Page 9: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Access Implementation: Binary One-to-Many

Page 10: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

ERD: Binary Many-to-Many

EMPLOYEE PROJECT

BillingRate

ASSIGNED_TO

Page 11: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Logical Schema: Binary Many-to-Many

Employee_ID Name Address Birthdate

EMPLOYEE

Project_ID Project_Name Start_Date

PROJECT

Employee_ID Project_ID Billing_Rate

ASSIGNED_TO

Page 12: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Logical Schema; Text

EMPLOYEE(Employee_ID, Name, Address, Birthdate)

ASSIGNED_TO(Employee_ID, Project_ID, Billing_Rate)

PROJECT(Project_ID, Project_Name, Start_Date)

Page 13: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Access Database

Page 14: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Access Database

Page 15: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Access Database

Page 16: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Access Implementation: Binary Many-to-Many

Page 17: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Logical Database DesignNormalization

Page 18: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical
Page 19: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Problem with Unnormalized Design

• No satisfactory primary key -- proj_num contains nulls, emp_num is duplicated

• Too easy for data entry to be inconsistent• Data redundancy gives rise to the following anomalies:

– Update anomalies– Insertion anomalies– Deletion anomalies

Page 20: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Normalization

• Process of assigning attributes to entities• Reduces data redundancy• Helps eliminate data anomalies that result from

redundancies

Page 21: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Normal Forms

• Normalization works through a series of stages called normal forms (1NF, 2NF, 3NF are most frequently encountered in business designs)

• From a structural point of view, 2NF is better than 1NF, and 3NF is better than 2NF

• Generally, the higher the normal form, the more joins are required to produce a specified output and the more slowly the system responds to end-user demands. Therefore, sometimes we may have to denormalize some portions of a database design in order to meet performance requirements.

Page 22: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Functional Dependency

• Normalization is based on the analysis of functional dependencies. A functional dependency is a constraint between two attributes, or two sets of attributes.

• For any relation R, attribute B is functionally dependent on attribute A if, for every valid instance of A, the value of A uniquely determines the value of B. This is notated as: A B

• Each normal form represents a state of a relation that results from applying simple rules regarding functional dependencies to that relation.

Page 23: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Examples of Functional Dependency

ISBN Title, First_Author_name

VIN Make, Model, Color

SSN Name, Address, Birthdate

Emp_ID, Course_Name Date_Completed

Page 24: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Candidate Keys

A candidate key is an attribute, or combination of attributes, that uniquely identifies a row in a relation. It must satisfy the following properties:

• Unique identification. For every row, the value of the key must uniquely identify that row. This implies that each nonkey attribute is functionally dependent on that key.

• Nonredundancy. No attribute in the key can be deleted without destroying the property of unique identification.

Page 25: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

First Normal Form

Remove repeating groups (multivalued attributes). A table with multivalued attributes or repeating groups is converted to a relation in first normal form by extending the data in each column to fill the cells that are empty.

Page 26: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical
Page 27: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical
Page 28: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Insertion Anomaly

In order to complete a row definition, a new employee must be assigned to a project. If an employee is not yet assigned, a phantom project must be created in order to complete the employee data entry.

Page 29: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Deletion Anomaly

If an employee quits, deletions must be made for every entry in which that emp_num appears. As such deletions are made, other vital data are lost.

For example, in our sample data, Darlene M. Smithson is the only DSS Analyst. If she leaves the company, we have to delete her in two places, and we will lose the information that a DSS Analyst is billed at $46 per hour.

Page 30: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical
Page 31: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Update Anomaly

Modifying data for an employee or a project requires updating many occurrences. For example, if Annelise Jones changes from Applications Designer to Database Designer, we would have to record this change in every project that Ms. Jones partakes in.

Page 32: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical
Page 33: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Second Normal FormA relation is in second normal form (2NF) if it is in first normal form and every

nonkey attribute is fully functionally dependent on the primary key. Thus no nonkey attribute is functionally dependent on part (but not all) of the primary key.

A relation that is in 1NF will be in 2NF if any one of the following conditions exist:• the primary key consists of only one attribute• no nonkey attributes exist in the relation• every nonkey attribute is functionally dependent on the full set of primary key

attributes

Page 34: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Partial Functional Dependency

A partial functional dependency is a functional dependency in which one or more nonkey attributes are functionally dependent on part (but not all) of the primary key.

Page 35: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Analyzing Functional Dependencies

Proj_Num Proj_Name Emp_Num Emp_Name Job_ClassChg_Hour Hours

Partial Dependency Partial Dependency

Full Dependency

Transitive Dependency

Page 36: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Decomposing 1NF Relation to Convert to 2NF

Proj_Num Proj_Name

Emp_Num Emp_Name Job_ClassChg_Hour

Proj_Num Emp_Num Hours

Primary key consists of only one attribute

Every nonkey attribute is functionallydependent on the full set of primary keyattributes

PROJECT RELATION

Primary key consists of only one attributeEMPLOYEE RELATION

ASSIGN RELATION

Page 37: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Third Normal Form

A relation is in third normal form (3NF) if it is in second normal form and no transitive dependencies exist.

Page 38: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Transitive DependencyA transitive dependency involves a functional dependency between two (or

more) nonkey attributes. For example, in the Employee relation, CHG_HOUR is functionally

dependent on JOB_CLASS. This causes the following problems• A new job class and its associated rate cannot be entered until an

employee has been assigned to the job class• If we delete an employee who is the only member of a particular job class,

we lose information about that job class and its associated rate

Page 39: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Decomposing 2NF Employee Relation to Convert to 3NF

Emp_Num Emp_Name Job_ClassChg_Hour

EMPLOYEE RELATION Transitive Dependency

Emp_Num Emp_Name Job_Class

EMPLOYEE RELATION

Job_Class Chg_Hour

JOB RELATION

Emp_Num Emp_Name Job_Code

EMPLOYEE RELATION

Job_Code Job_Class

JOB RELATION

Chg_Hour

Page 40: Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical

Putting it back together: