44
Supplemental Topic: DATABASES

Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

  • View
    218

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Supplemental Topic:

DATABASES

Page 2: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

What is Data?

• anything you want/need to know– facts– documents– sounds– images

• Database is an organized collection of related data– easily stored, manipulated, retrieved– common domain of interest

Page 3: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Data vs. Information

• data is cheap, information is useful

Baker, Kenneth D. 324917628Doyle, Joan E. 476193248Finkle, Clive R. 548429344Lewis, John C. 551742186McFerran, Debra R. 409723145Sisneros, Michael 392416582

Page 4: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

InformationClass Roster

Course: 615-230 Semester 1, 2002

Database Concepts

Tutorial: 12

Name ID Grade

Baker, Kenneth D. 324917628 HD

Doyle, Joan E. 476193248 HD

Finkle, Clive R. 548429344 HD

Lewis, John C. 551742186 HD

McFerran, Debra R. 409723145 HD

Sisneros, Michael 392416582 HD

Page 5: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Terminology

Database – a collection of inter-related, shared, and controlled data

Database Management System (DBMS) – an application software that allows users to create and operate a database (MS Access, Paradox, Oracle, Sybase, DB2).

Traditional file system – a system where each application has its own set of files (next slide)

Page 6: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Traditional File Management

Customer File

Savings Account File

Customer File

Loan Account File

Customer File

Checking Account File

FilesSavings AccountSystem

Loan AccountSystem

CheckingSystem

Application Programs Users

Page 7: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

DBMS facilitates the management of database

Database

Savings AccountSystem

Loan AccountSystemCheckingSystem

Application Programs Users

Customer Table

Savings Account Table

Loan Account Table

Checking Account Table

DatabaseManagement System

Page 8: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

DBMS vs. Traditional File Systems

Data redundancy and inconsistency is reduced Information is easier to access and use

DBMS unifies otherwise distinct files by specifying relationships between files

Maintaining data and ensuring security and integrity of data is simpler control is centralized

Page 9: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Physical structure of data and physical access mechanism are independent of application programs changes in physical storage structure and access

mechanism do NOT require changes to application programs

DBMS vs. Traditional File Systems

Page 10: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Three Database Models of DBMS

Hierarchical: Top-down, Tree-like structure Network: (Graph) Record-type connected in

one-one and one-many relationship Relational: Two-dimensional tables related

by common data elements

Page 11: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Three Database Models

Hierarchical Model - data is organized like a tree; only one to many relationships

Dept. A Dept. B

Division 1

Employee 1

Employee 2

Employee 3

Dept. A Dept. B

Division 1

Employee 1

Employee 2

Employee 3

Network Model- data is organized like a graph; one to many and many to many relationships

Page 12: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Three Database Models

Relational Model - data is organized into two-dimensional tables flexible approach to establish relationships

tables linked via a common data element MS-Access is an implementation of the relational

model

Page 13: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Summary: Three DBMS models

Problem Hierarchical Network Relational

Dimension DBMS DBMS DBMS

Data relationship

One-to-many Many-to-many

Flexible

Transaction volume

High Medium Medium, but improving

Flexibility of info. retrieval

Low Low High

Ease of use for end users

Low Low High

Page 14: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Relational Databases

Page 15: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Basic Definitions

• Entity

• Attribute

• Relationship

• Database

• DBMS

• Relational Database

Page 16: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Terminology

entity - a person, place, thing or event

attribute - a characteristic of an entity

products orders customersclassrooms

Examplesname, pricedate, amountname, addressnumber, building, size

Examples

Page 17: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Entity

Just like a noun; a person, place, thing, or event.

Examples

Page 18: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Attribute

Property of an entity (adjective, adverb)

Examples

Page 19: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Relationship

Association between entities

Examples

Page 20: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Database

Structure that can house information about multiple types of entities, the attributes of these entities, and the relationships among the entities.

Examples

Page 21: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Database Management Systems

Software product through which users interact with a database.

Examples

Page 22: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Relational Definitions

• Relation: “A named, two-dimensional table of data.”• Structure notation:

EMPLOYEE1(Emp_ID,Name,Dept_Name,Salary)DEPARTMENT(DEPT_Name,Location,Fax)

Page 23: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

… properties

• each row is unique

• each column (attribute) has a unique name (though can be same domain)

• sequence of columns irrelevant

• sequence of rows irrelevant (but can be controlled for output)

Page 24: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Entity:

• A “thing” in the real world with an independent existence

• A person, place, thing, or event

• Physical: such as person and place

• Conceptual: such as job, company, college course

Page 25: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Terminology - The Data Hierarchy

Database

Files (Tables)

Records (Rows)

Fields (Columns)

a group of logically related files or tables

a collection of related records

a group of related fields

a group of characteristics

Page 26: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

The Data Hierarchy

Database

Files (Tables)

Records (Rows)

Fields (Columns)

Customer Database

CustomerTable

OrderTable

InvoiceTable

01 John Smith 22 Pinewood Ave Sudbury MA ..02 Karla Stokes 13 Whaley Ave New Haven CT …03 George Vasta 100 Brook St. Killingly CT..

George Vasta (Name Field)

01 George Vasta 100 Brook St. Killingly CT

Page 27: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Keys

primary key - a field which uniquely identifies a record

John Smith 22 Pinewood Ave Sudbury MA .. Karla Stokes 13 Whaley Ave New Haven CT …George Vasta 100 Brook St. Killingly CT..

000010000200003

CustomerId Name Address

foreign key - a field in one table which references a field of another table

9/30/98 $125.67 10/1/98 $ 75.90 10/2/98 $ 82.75

000010000200003

OrderId CustomerId Date Amount000010000200001

Customer Table

Order Table

Page 28: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Two Relational Integrity Rules

Entity Integrity - All records must be uniquely identified (no nulls or duplicates)

Referential Integrity - Foreign key values must match field values in reference table (no dangling references)

Page 29: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Two Relational Integrity Rules

Entity Integrity - All records must be uniquely identified (no nulls or duplicates)

00001 John Smith 22 Pinewood Ave Sudbury MA ..00001 Karla Stokes 13 Whaley Ave New Haven CT … George Vasta 100 Brook St. Killingly CT..

No

CustomerId Name Address

Customer Table

Page 30: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Two Relational Integrity Rules

Referential Integrity - Foreign key values must match field values in reference table (no dangling references)

John Smith 22 Pinewood Ave Sudbury MA ..Karla Stokes 13 Whaley Ave New Haven CT George Vasta 100 Brook St. Killingly CT..

9/30/98 $125.67 10/1/98 $ 75.90 10/2/98 $ 82.75

000010000200003

OrderId CustomerId Date Amount

000010000200005

000010000200003

No

CustomerId Name AddressCustomer Table

Order Table

Page 31: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Schema for four relations (Pine Valley Furniture)

CUSTOMER (Customer_ID,Customer_Name,Address,City,State,Zip)ORDER (Order_ID,Order_Date,Customer_ID)ORDER_LINE (Order_ID,Product_ID,Quantity)PRODUCT (Product_ID,Product_Description,Product_Finish,Unit_Price,On_Hand)

Page 32: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Instance of a relational schema

Page 33: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Relation Normalization

In order for relational structures to be useful and manageable, the relational tables must be “normalized”

Page 34: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

The Three Steps of Normalization

Unnormalized Relationship

Normalized Relations(1NF)

Second Normal (2NF) Relations

Third Normal Form (3NF) Relations

Step 1:Remove Repeating Groups

Step 2:Remove Partial Dependencies

Step 3:Remove Transitive Dependencies

Page 35: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

One-to-One Relationship

ID Husband_Name

112-09-2293 John Smith

ID Husband_ID Wife_Name

221-90-9322 112-09-2293 Joann Smith

Page 36: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

One-to-Many Relationship

Customer_ID Customer_Name

112 ABC Corp

Order_Number Customer_ID Order_Amount

001 112 20

003 112 10

Page 37: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Establishing Many to Many Relationships

DepartmentID

DepartmentName

Department Table

DepartmentID

EmployeeID

Dept_X_EmployeeTable

EmployeeId

Name

Address

Employee Table

1

M

M

1•Need a “Cross” Table

•Specify two one-to-many relationships

Page 38: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Entity Relationship Diagrams

• used to design the database (storage) component

• shows relationships between entities– entity - person, place, thing, event

• symbols

Relationship Entity

Page 39: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Entity Relationship Diagram - Example

Patient

InvoicesPayments

Servicesis provided

are accounted for by

makes

are applied to

1 M

1

M1

MMM

1:M == 1 to many relationshipM:M == many to many relationship

Page 40: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Entity-Relationship ModelExample of schema in the entity-relationship model

Page 41: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

A Sample Relational Database

Page 42: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Data Dictionary : Properties(also called meta-data)

Data Elements NAME: Last-Name (Attribute)DEFINITION: Designates patients last

name.TYPE: characterLENGTH: 15ALIASES: Last NameFILE WHERE FOUND: Client, Payment PROCESS 1.0 Capture PaymentWHERE USED: 2.0 Track Payments 3.0 Prepare Bills

A data dictionary is used in solution design to define and describe each piece of data and the data groupings used in information systems.

Page 43: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Database Design Process Step 1

• Information-level design– gather user requirements– design a database that meets requirements as

cleanly as possible– independent of DBMS

Page 44: Supplemental Topic: DATABASES. What is Data? anything you want/need to know –facts –documents –sounds –images Database is an organized collection of related

Database Design ProcessStep 2

• Concerned with characteristics of specific DBMS

• Must resolve issues such as– column names– data type– number of columns– data length