37
+ Relational Model IST210 Class Lecture

+ Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

Embed Size (px)

Citation preview

Page 1: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

+

Relational Model

IST210 Class Lecture

Page 2: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

+Premiere Products

A new company that is going to sells random merchandise via sales representatives

You have been hired by HR to develop their employee data requirements

What information would you want to keep about each employee?

Page 3: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

+Premiere Products

Now you have been hired by the sales department.

They want to know what information they will need to keep track of on sales orders.

What information do you think need?

Page 4: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

+Premiere Products Sales Order

Page 5: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+Entity

An entity is something of importance to a user that needs to be represented in a database.

An entity is a person, place, object, event, or idea for which you want to store and process data

An entity represents one theme or topic.

In an entity-relationship model (discussed in Chapter 4), entities are restricted to things that can be represented by a single table.

Page 6: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+Relation

A relation is a two-dimensional table that has specific characteristics.

The table dimensions, like a matrix, consist of rows and columns.

Page 7: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+Characteristics of a Relation

1. Rows contain data about an entity.

2. Columns contain data about attributes of the entity.

3. Cells of the table hold a single value.

4. All entries in a column are of the same kind.

5. Each column has a unique name.

6. The order of the columns is unimportant.

7. The order of the rows is unimportant.

8. No two rows may be identical.

Page 8: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+A Sample Relation

EmployeeNumber FirstName LastName

100 Mary Abernathy

101 Jerry Cadley

104 Alex Copley

107 Megan Jackson

Page 9: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+A Nonrelation Example

EmployeeNumber Phone LastName

100 335-6421, 454-9744

Abernathy

101 251-7789 Cadley

104 610-9850 Copley

107 299-9090 Jackson

Cells of the table hold multiple values

Page 10: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+A Nonrelation Example

EmployeeNumber Phone LastName

100 335-6421 Abernathy

101 215-7789 Cadley

104 610-9850 Copley

100 335-6421 Abernathy

107 299-9090 Jackson

No two rows may be identical

Page 11: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+Terminology

Synonyms …

Table Row Column

File Record Field

Relation Tuple Attribute

Page 12: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+A Relational Database

A relational database is a collection of tables

Tables are called relations

This term is the basis for the name relational database

Page 13: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have
Page 14: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have
Page 15: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+A Key

A key is one (or more) column(s) of a relation that is (are) used to identify a row.

Page 16: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+Uniqueness of Keys

Unique Key Nonunique Key

Data value is unique for each row.Consequently, the key will uniquely identify a row.

Data value may be shared among several rows.Consequently, the key will identify a set of rows.

Page 17: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+A Composite Key

A composite key is a key that contains two or more attributes.

For a key to be unique, it must often become a composite key.

Page 18: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+Composite Key Characteristics

To identify a family member, you need to know a FamilyID, a FirstName, and a Suffix (e.g., Jr.).

The composite key is:

(FamilyID, FirstName, Suffix).

One needs to know the value of all three columns to uniquely identify an individual.

Page 19: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+A Candidate Key

A candidate key is called “candidate” because it is a candidate to become the primary key.

A candidate key is a unique key.

Page 20: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+A Primary Key

A primary key is a candidate key chosen to be the main key for the relation.

If you know the value of the primary key, you will be able to uniquely identify a single row.

Page 21: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+A Surrogate Key

A surrogate key is a unique, numeric value that is added to a relation to serve as the primary key.

Surrogate key values have no meaning to users and are usually hidden on forms, queries, and reports.

A surrogate key is often used in place of a composite primary key.

Page 22: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+Surrogate Key Example

If the Family Member primary key is FamilyID, FirstName, Suffix, it would be easier to append and use a surrogate key of FamMemberID.

FamilyID, FirstName and Suffix remain in the relation.

Page 23: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+Relationships Between Tables

A table may be related to other tables.

For example An Employee works in a Department A Manager controls a Project

Page 24: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+A Foreign Key

To preserve relationships, you may need to create a foreign key.

A foreign key is a primary key from one table placed into another table.

The key is called a foreign key in the table that received the key.

Page 25: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+Foreign Key Example I

Employee

EMPID

FirstName

MgrID

Manager

MgrID

MgrName

Foreign Key

Primary Key

Page 26: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

+

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

Foreign Key Example II

Department

DeptID

DeptName

Location

Employee

EmpID

DeptID

EmpNameForeign Key

Primary Key

Page 27: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+The Null Value

A Null value means that no data was entered.

This is different from a zero, space character, or tab character.

Page 28: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+The Problem of the Null Value

A Null is often ambiguous. It could mean… The column value is not appropriate for the

specific row. The column value is not decided. The column value is unknown.

Each may have entirely different implications.

Page 29: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+Functional Dependency

Functional Dependency—A relationship between attributes in which one attribute (or group of attributes) determines the value of another attribute in the same table

Illustration… The price of one cookie can determine the

price of a box of 12 cookies.(CookiePrice, Qty) BoxPrice

Page 30: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+Determinants

The attribute (or attributes) that we use as the starting point (the variable on the left side of the equation) is called a determinant.

(CookiePrice, Qty) BoxPrice

Determinant

Page 31: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+

Normalization

Page 32: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

+Normalization

Normalization is the transformation of complex user views and data to a set of smaller, stable, and easily maintainable data structures.

Normalization creates data that are stored only once on a file.

The exception is key fields.

The data structures are simpler and more stable.

The data is more easily maintained.

Page 33: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

+Three Steps of Data Normalization

The three steps of data normalization are: Remove all repeating groups and

identify the primary key. Ensure that all nonkey attributes

are fully dependent on the primary key.

Remove any transitive dependencies, attributes that are dependent on other nonkey attributes.

Page 34: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

+ Three Steps of Normalization

Page 35: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

+First Normal Form (1NF)

Remove any repeating groups.

All repeating groups are moved into a new table.

Foreign keys are used to link the tables.

When a relation contains no repeating groups, it is in the first normal form.

Page 36: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

+Second Normal Form (2NF)

Remove any partial dependencies.

A partial dependency is when the data are only dependent on a part of a key field.

A relation is created for the data that are only dependent on part of the key and another for data that are dependent on both parts.

Page 37: + Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have

+Third Normal Form (3NF)

Remove any transitive dependencies.

A transitive dependency is when a relation contains data that are not part of the entity.

The problem with transitive dependencies is updating the data.

A single data item may be present on many records.