Relational Database. I. Relational Database 1. Introduction 2. Database Models 3. Relational Database 4. Entity-Relationship Models 5. RDB Design Principles.

Post on 05-Jan-2016

233 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

Transcript

Relational Database

I. Relational Database

1. Introduction

2. Database Models

3. Relational Database

4. Entity-Relationship Models

5. RDB Design Principles

1. Introduction

Database Is a collection of related data Is persistent

Database Management SystemSoftware system to add, delete, search,

and modify the data in the DBTo provide various ways to view the data in

the DB

2. Database Models

Flat Database

Hierarchical DB

Network DB

Relational DB

Flat Database

Flat Database (Library DB)RedundancyPublisher name is repeatedPublisher phone number is repeatedAuthor phone is repeated If publisher address is included, … ?

Update AnomaliesTo modify publisher phone, all need to be

modified

Insertion AnomalyA new publisher, with no data about book,

author, and other details which are not available, cannot be included.

Deletion Anomaly If a book is deleted, its publisher data, or

author data, can also be eliminated (e.g., last book in the list)

Solution

Break up Flat-file DB into Separe Tables

Tables (Library DB)

Hierarchical DB Model

Agents

Agency Database

PaymentsEngagementsSchedules

Entertainers Clients

(This and remaining slides on DB Models are adapted from Database Design for Mere Mortals, Michael Hernandez, Addison Wesley, 1999)

Back to Ref Ing

Hierarchical DBM Characteristics

One table acts as a root of an inverted tree; other tables are branchesEach child table may have only one parent tableEach parent table may have many child tablesTo access any data, must start at root table

Hierarchical DBM Advantages & Disadvantages

Advantages: Data retrieve is fast, because table structure is

explicitly linked Referential integrity is built in

Disadvantages: Difficult to store data in child table when no

corresponding record exists in parent tables. E.g., a new entertainer cannot be entered in the DB until a specific Agent is assigned

Difficult to model complex relationships Difficult to add new tables

Referential Integrity

Each record in a child table is linked to an existing record in the parent table. E.g., every Payment record is associated with a particular Client.

If a record is deleted in a parent table,all associated record in child tables are also deleted. E.g., If a particular Client record is deleted, all related records in Payments and Engagements are deleted—no orphans.

Network Database Model

Agents

Agency Database

Musical StylesEngagementsPayments

Clients Entertainers

represents manages

performsschedulesmakes plays

Network DBM Characteristics

Invented to address problems with the Hierarchical DB Model

A child table can have more than one parent table

Can go up or down the structure. E.g., to answer “Who was the agent that booked a particular engagement?”, start with Engagements, Clients, then to Agents.

Relational DatabaseCollection of tables e.g., books, authors, publishers, clients

Each cell in a table is atomic i.e., no formulas, pointers, but single data item

Tables are linked by common values in selected columns i.e., not by pointers

Books Table

Publishers Table

Basic TerminologyData & Information

These are data valuesKashimata 25 October 31 25000

This is informationCustomer’s last Name: KashimataAge: 25Birthday: October 31Savings Account Balance: $25,000

Basic TerminologyNull

Null, zero, and blank Age = Null

age is undefined Age = 0

age is 0 MiddleName = Null

middle name is undefined MiddleName = “”

person has no middle name MiddleName = “ “

no middle name, takes up 1 byte

Basic TerminologyTable, Record, Field

Formal Informal Non-relational

relation table database

tuple row record

attribute column field

Basic TerminologyTable

Table (Books Table)Represents an entity (category) of objects

with its (relevant) attributesConsists of rows (records) and columns

(fields) In the Books table, each record is an

instance of the Books category.Each field represents an attribute

Basic TerminologyAttributes (fields)

To provide specific information about entityTo help identify individual entities--e.g., ISBN for books, SSN for employee, Sales_ID for sales.To describe relationship between entity entities in different entity classesFor example...

Your Turn. Identify Attributes..

Entity Classes for School DatabaseStudentsFacultyStaffBuildingsRoomsCourseClass

Identify Attributes...

Entity Classes For a Bank DatabaseCustomersAccountEmployeeTransaction

Basic TerminologyKeys

SuperkeySet of attributes to identify a record

uniquely in a set--e.g., to distinguish one book from all others. ISBN, ISBN+TITLE, ISBN+TITLE+AUTHOR

Key or Candidate KeyMinumum superkey. E.g., ISBN

Primary KeyA Key that is chosen for a particular table

Primary Key

Employee Class FirstName LastName SSN PhoneNumber DateOfBirth E-mail

Candidate Key SSN FirstName

+LastName + DateOfBirth

E-mail? E-mail + DateOfBirth

Primary Key SSN

Types of Relationships(Library DB)

How are the tables associated with each other, so that information can be extracted from multiple tables?

Publishers

Authors

Books

Types of Relationships

1 to many (most common) A A publisherpublisher may publish may publish manymany books, but each books, but each bookbook may have only may have only oneone publisher publisher

may to many (undesirable) A A bookbook may be written by may be written by manymany authors, and an authors, and an authorauthor may write may write manymany books. books.

1 to 1 (not as common) One One authorauthor has at most has at most oneone secretary, and each secretary, and each secretarysecretary works for only works for only oneone author author

One-To-Many Relationship

One record in Publishers can be related to many records in Books

But, each record in Books can be associated with only one record in Publishers

Publishers Books

∞1

Publishers Books

1 1

Many-to-Many Relationship

One record in Authors can be related to many records in Books

And, each record in Books can be associated with many records in Authors

Authors Books

∞1

Authors Books∞ 1

One-to-OneRelationship

One record in Authors can be related to only one record in Secretaries

And, each record in Secretaries can be associated with only record in Authors

Authors Secretaries1

1

Authors

11

Secretaries

ExampleDatabase TypeLibrary

TablesBooksPublishers

One-to-Many Relationship?Yes

Why?

ExampleDatabase TypeOrder Tracking

TablesCustomersOrders

One-to-Many Relationship?Yes

Why?

ExampleDatabase TypeSchool Scheduling

TablesClassesStudents

One-to-Many Relationship?No (Many-to-Many)

Why?

Data Integrity

Table-level integrity E.g., no duplicate records (by defining a primary

key)

Field-level integrity E.g., do all “State” field require 2 characters? Each field contains a single atomic value?

(e.g., Author field should not contain 2 authors

Relationship-level integrity E.g., no many-to-many relationships Prevent “orphans.” e.g., if a publisher record is

deleted, a book record is left without a publisher.

top related