Вы находитесь на странице: 1из 34

Database Fundamentals - A

Review
Victor Raj, PhD
Murray State University

Objectives
In this module, we will review the
following:
Primary key & its characteristics
Composite Keys
Foreign keys
Anomalies & Relationships
Dependencies and Normalization
CIS609 (Review)

Tables
Table: two-dimensional structure
composed of rows and columns

CIS609 (Review)

What is a database
table?

CIS609 (Review)

Primary Key
Each row in a table must be uniquely
identifiable

A Primary Key is one or more attributes that


determine other attributes

PKs role is based on determination


If you know the value of attribute/column A, you
can determine the value of attribute B

If you know a persons M# (at Murray), you can


determine their name

CIS609 (Review)

Keys (continued)
Composite key
A key that is composed of more than one attribute

Key attribute
Any attribute that is part of a key

CIS609 (Review)

The importance of null


Nulls:
No data entered. Or the absence of a value
Not permitted in primary key
Should be avoided in other attributes
Can represent
An unknown attribute value; a known, but missing,
attribute value; a not applicable condition

CIS609 (Review)

Nulls (continued)
Issues with Nulls:
Can create problems when functions such
as COUNT, AVERAGE, and SUM are used

Can create logical problems when


relational tables are linked it may not
retrieve some rows (costly lapse!)

Databases need special functions to deal


with them
CIS609 (Review)

Back to Keys
Foreign key (FK)
An attribute whose values match primary key values
in a related table

Referential integrity
FK MUST contain a value that refers to an existing
valid row in another table

CIS609 (Review)

Integrity rules

CIS609 (Review)

10

Integrity Rules (contd)


Many RDBMs enforce integrity rules
automatically

However, it is safer to manage entity and


referential integrity rules in the application allows easier database migration.

Developers use flags to avoid nulls


represents unknown
CIS609 (Review)

11

Redundancy
Simply means duplication
Controlled redundancy:
Makes the relational database work
Facilitates linking of tables together
Multiple occurrences of values not redundant
when required to make the relationship work

Redundancy exists only when there is


unnecessary duplication of attribute values
CIS609 (Review)

12

Excessive redundancy
Anomalies
Insert - You cannot add a row without being forced to
add information that may not yet be available

Delete - Deleting a row will result in the loss of other


important information that you had no desire of
losing

Update - You are forced to make changes repeatedly


See Video linked on canvas
http://youtu.be/G9SA0Yv-o28

CIS609 (Review)

13

Update anomaly
Whats the problem here?

CIS609 (Review)

14

Deletion anomaly
Mnumbe
r

Last
name

First
name

Course

Time

Room

M001

Smith

Job

ACC200 11:30
MW

BB302

M002

Smith

Jhansi

ACC200 12:30
TR

BB302

M001

Smith
Job
BUS215 12:30
What challenges do you face
MW
when you delete a student? Or a
Kline
Smith
course?BUS215 12:30
MW

BB206

M003
CIS609 (Review)

BB206
15

Insertion anomaly
Mnumbe
r

Last
name

First
name

Course

Time

Room

ACC200 11:30
MW

BB302

ACC200 12:30
TR

BB302

BUS215 12:30
Can you list all available courses?
MW
(Recall definition of PK No NULLS
allowed)
CIS609 (Review)

BB206

16

A good database designer


can spot and fix such
anomalies intuitively

How do you fix these anomalies?


understand database relationships
CIS609 (Review)

17

Relationships within the


Relational Database
1:M relationship
Very common

1:1 relationship
Should be rare in any relational database
design

M:N relationships
Also very common, but missed by novices
Converted to two (or more) 1:M relationships
CIS609 (Review)

18

The 1:M Relationship


Relational database norm
Found in any database environment

CIS609 (Review)

19

Implementing 1:M

CIS609 (Review)

20

The 1:1 Relationship


One entity related to only one other
entity, and vice versa

Sometimes means that entity

components were not defined properly

Could indicate that two entities actually


belong in the same table

Certain conditions absolutely require


their use

CIS609 (Review)

21

The M:N Relationship


Implemented by breaking it up to produce a
set of 1:M relationships

If two entities STUDENTS, COURSES have


a M:N relationship, create a THIRD table to
tie these two together (example follows)

You must include (at the least) the primary


keys of the tables to be linked in this THIRD
table to ensure referential integrity
(remember that?)
CIS609 (Review)

22

CIS609 (Review)

23

Ensures
referential
integrity...
Cannot enroll
students in
classes that
dont exist. Or
enroll students
that dont exist
in STUDENT

CIS609 (Review)

24

This separation
ensures that the
course
information (title,
credits etc.) are
not repeated
unnecessarily.

CIS609 (Review)

25

Degree

CIS609 (Review)

26

Now you know


The importance of keys
Controlled redundancy
The types of anomalies and the dangers
they present

The degree and types of relationships


and how to spot them

now for Normalization


CIS609 (Review)

27

Normal forms
First no repeating groups, but very
likely to have partial dependencies

Second no repeating groups, no partial


dependencies, but very likely to have
transitive dependencies

Third - no repeating groups, no partial


dependencies, and no transitive
dependencies.
CIS609 (Review)

28

Repeating groups

CIS609 (Review)

29

Partial dependency

CIS609 (Review)

30

Transitive and partial


dependency

Removing all but the functional dependency will


result in a 3NF design. Removal is accomplished
by splitting the table into a set of related tables.
CIS609 (Review)

31

Summary - 1
Tables are basic building blocks of a
relational database

Keys are central to the use of relational


tables

Keys define functional dependencies


Primary key
Foreign key
CIS609 (Review)

32

Summary - 2
Each table row must have a primary key

that uniquely identifies the other


attributes
Tables linked by common attributes
Good design begins by identifying entities,
attributes, and relationships
1:1, 1:M, M:N (connectivity)
Unary, binary, ternary (degree)
CIS609 (Review)

33

Summary - 3
Normalization
First no repeating groups, will have partial
dependency

Second no partial dependency or repeating


groups, will have transitive dependency

Third no transitive or partial dependency or


even repeating groups.

Normalization is good for maintaining


data consistency and storage efficiency.
CIS609 (Review)

34

Вам также может понравиться