39
What's a Database A Database Primer

What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Embed Size (px)

Citation preview

Page 1: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

What's a Database

A Database Primer

Page 2: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Let’s discuss databases Why they are hard Why we need them

Page 3: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Advantages of Database Processing

More information from the same amount of data

Share Data Balance Conflicting Requirements Control Redundancy Facilitate Consistency Improve Integrity Expanding Security Increasing Productivity Provide Data Independence

Page 4: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

More information from the same amount of data Data + Processing =

Information

Page 5: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Share Data

Islands of data are difficult to share

Conflicts with file structures, naming conventions

Page 6: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Balance Conflicting Requirements Different parts

of the business have different uses for the data

Page 7: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Control Redundancy

Single authoritative source

Page 8: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Facilitate Consistency

One source – no conflicting data

Page 9: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Improve Integrity

Refer to single authoritative source

Ensure that single source is correct

Page 10: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Expanding Security

Put all your eggs in one basket

Watch the basket

Page 11: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Increasing Productivity

Only one place to store

Only one place to look

Prepare data once

Page 12: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Data Independence

Changes in the physical structure do not affect the logical structure= scalability

Page 13: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Topics Manual database example

Page 14: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Structure Fields, Records, Files Columns, Rows, Tables Attribute, Tuple, Relations Rules: Types of data you can

enter Field Column Attribute

Field Name Column Name Attribute Name

Record Row Tuple

File Table Relation

Page 15: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

More Complex Model What if….

Page 16: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

A Database is…

Tables Relationships Queries Forms Reports Programs

Page 17: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

A Student Record

Page 18: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

A Few Students

Page 19: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Table View

Page 20: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

A Few Students

Kelly moves

Page 21: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Redundant Data leads to Inconsistent Data

Bud moved too but now the addresses don’t match!His record still has the old address.

Page 22: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

A Solution?

Page 23: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

A Solution?Move the data that is common to several records to a new table

Page 24: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

A Solution!

Page 25: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

A Solution

Page 26: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Relationships

Primary Keys

Foreign Key

Page 27: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Even More Relationships

Page 28: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Lots of Tables

Page 29: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Normalize? 1st Normal Form

At each row-column intersection, there must be one, and only one, value.

For example, a database would violate the rule for the first normal form if it stores, in a single row-column intersection, all of the scores for a bowler

Page 30: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

2nd Normal Form Every non-key column must depend

upon the entire primary key. No non-key column is dependent on

only a portion of the primary key If the primary key is composite-made up of

more than one component - no non-key column can be a fact about a subset of the primary key.

e.g. compound key firstname+lastname+province code would violate this rule, if another column was functionally dependent on the province code (John+Smith+BC) if “British Columbia” is functionally dependent on the code BC

Only an issue if you have compound primary keys

e.g. name + product code

Page 31: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

3rd Normal Form No non-key column can depend

on another non-key field Each column must be a fact about the

entity identified by the primary key All determinants are candidate keys e.g. in a table about people that

contains a column with province codes, and another column with the full name of the province, the province code is a determinant of the full name, but is not a candidate key for the table of people

Defn: Determinant

A column that determines another column is a determinant

Page 32: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

4th Normal Form There must not be any

independent one-to-many relationships between primary key columns and non-key columnsi.e. There are no multivalued dependencies

ID Answer1 Answer2 Answer3

223 A B C

224 B C A

Page 33: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

5th Normal Form Tables are broken into the

smallest possible pieces in order to eliminate all redundancy within a table.

In extreme cases, tables in fifth normal form may consist of a primary key and a single non-key column.

High integrity Slow performance Redundancy due to extensive use of

foreign keys

Page 34: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Summary – Normal Forms

Normal Form

Meaning/Conditions Notes

First No repeating groups exist

Second 1NF + no nonkey column is dependent on a portion of the primary key

If primary key is a single column then automatically 2NF

Third 2NF + the only determinants are candidate keys

Boyce-Codd Normal Form

Fourth 3NF + no multivalued dependencies

Page 35: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

A Historical Perspective•Physical collections

•Flat Files

•Lists

•Indexes and pointers

Page 36: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Other Perspectives

•Hierarchical Structures

•Folders and Files

•Inverted Tree

•Organization Charts

•Single parent – many child relationships

•Network

•Multi – parent – many child relationships

Page 37: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

What do you normalize? Office

Supplies Inventory

Office Kitchen Bathroom

Page 38: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them

Relational Fields, Records, Files Columns, Rows, Tables Attribute, Tuple, Relations Structure and Relationships

Page 39: What's a Database A Database Primer Let’s discuss databases n Why they are hard n Why we need them