Download Relational Modeling

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Entity–attribute–value model wikipedia , lookup

Versant Object Database wikipedia , lookup

Concurrency control wikipedia , lookup

Database wikipedia , lookup

Data vault modeling wikipedia , lookup

Clusterpoint wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

Transcript
+
Relational Model
IST210 Class Lecture
+
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?
+
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?
+
Premiere Products Sales Order
+
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.
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.
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.
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
KROENKE and AUER - DATABASE CONCEPTS (6th Edition)
Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall
+
A Nonrelation Example
Cells of the table hold multiple values
EmployeeNumber
Phone
LastName
100
335-6421, 454-9744
Abernathy
101
251-7789
Cadley
104
610-9850
Copley
107
299-9090
Jackson
KROENKE and AUER - DATABASE CONCEPTS (6th Edition)
Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall
+
A Nonrelation Example
No two rows may be identical
EmployeeNumber
Phone
LastName
100
335-6421
Abernathy
101
215-7789
Cadley
104
610-9850
Copley
100
335-6421
Abernathy
107
299-9090
Jackson
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
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
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.
KROENKE and AUER - DATABASE CONCEPTS (6th Edition)
Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall
+
Uniqueness of Keys
Unique Key
Data value is unique
for each row.
Consequently, the
key will uniquely
identify a row.
Nonunique Key
Data value may be
shared among
several rows.
Consequently, the
key will identify a set
of rows.
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.
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.
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.
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.
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.
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.
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
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.
KROENKE and AUER - DATABASE CONCEPTS (6th Edition)
Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall
+
Foreign Key Example I
Employee
Manager
Primary Key
EMPID
MgrID
FirstName
MgrName
MgrID
Foreign Key
KROENKE and AUER - DATABASE CONCEPTS (6th Edition)
Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall
+
Foreign Key Example II
Department
Employee
Primary Key
DeptID
EmpID
DeptName
DeptID
Location
Foreign Key
KROENKE and AUER - DATABASE CONCEPTS (6th Edition)
Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall
EmpName
+
The Null Value
A
Null value means that no data was
entered.
 This
is different from a zero, space
character, or tab character.
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.
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)
KROENKE and AUER - DATABASE CONCEPTS (6th Edition)
Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall
BoxPrice
+
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)
Determinant
KROENKE and AUER - DATABASE CONCEPTS (6th Edition)
Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall
BoxPrice
+
Normalization
KROENKE and AUER - DATABASE CONCEPTS (6th Edition)
Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall
+
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.
+
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.
+ Three Steps of Normalization
+
First Normal Form (1NF)
 Remove
any repeating groups.
 All
repeating groups are moved into a new
table.
 Foreign
 When
keys are used to link the tables.
a relation contains no repeating
groups, it is in the first normal form.
+
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.
+
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.