Relational Databases

33
Relational Databases

description

Relational Databases. What Is A Relational Database?. Created by Dr. E.F. Codd A database is a collection of tables and other “objects” that are related and collectively describe an entity. Other objects are forms, queries, reports, modules.. Advantages Of Database. - PowerPoint PPT Presentation

Transcript of Relational Databases

Page 1: Relational Databases

Relational Databases

Page 2: Relational Databases

What Is A Relational Database?

Created by Dr. E.F. CoddA database is a collection of tables

and other “objects” that are related and collectively describe an entity.

Other objects are forms, queries, reports, modules.

Page 3: Relational Databases

Advantages Of Database

Store data only once - lower costReduces errorsEliminate data redundancyAvoid duplicate processingSimplify maintenance

Centralize data management & security

Page 4: Relational Databases

Advantages Of Database

Offer greater flexibilitySimplify report modifications and

updatesProvide ad-hoc query capabilitiesCross functional data analysisPermits multiple use and simultaneous

data analysis

Page 5: Relational Databases

Disadvantages Of Database Systems

Increased costs (usually offset by savings)Hardware requirementsThe software itselfDatabase administrator

Page 6: Relational Databases

Disadvantages Of Database Systems

Centralized management and security controlSystem operation becomes criticalErrors in data entry effects all usersPotential disputes over data ownership

Page 7: Relational Databases

Tables

Fundamental storage structures for data Tables are sometimes called filesLooks like a spreadsheet Consist of rows (TUPLES) which are

the equivalent of a record and columns (ATTRIBUTES) which are the equivalent of a field

Page 8: Relational Databases

Table Terms

Primary key - An attribute (column) that uniquely identifies a given row so the system can distinguish each record of a table PRIMARY KEYS CAN’T BE NULL!

Foreign key - An attribute (column) in one table that must match the primary key in another table. Used to join tables together.

Composite (concatenated) key - A primary key that consists of more than a single column.

Page 9: Relational Databases

Table Rules

No duplicate tablesNo duplicate rows or columns in tableSequence of rows/columns doesn’t

matterEach table must have a primary keyThe primary key CANNOT be nullEach table is about ONE concept

Page 10: Relational Databases

Joining Tables

Customer ID Company Name Contact Phone Number Credit Limit

Customer IDInvoice ID

Quantity

Customer POEmployee IDInvoice Date

Invoice ID Inventory ID

Order Date

Unit Price Discount

Inventory ID Item ID Caffeinated Price On Hand

Page 11: Relational Databases

11

One-to-One Relationships

Only one matching recordUses primary key for both tablesUse to limit access to information

Page 12: Relational Databases

12

One-to-One Relationships (cont.)

Page 13: Relational Databases

13

One-to-Many Relationships

Most common type of relationshipRelated between primary and foreign keysCan have many related recordsReferential integrity prevents orphaned records

Page 14: Relational Databases

14

One-to-Many Relationships (cont.)

Page 15: Relational Databases

15

Many-to-Many Relationships

One order, many productsOne product, many ordersNot directly supported between tablesUse an Intersection table to relate

Page 16: Relational Databases

16

Many-to-Many Relationships (cont.)

Page 17: Relational Databases

17

Relational Database Design Relationships and Referential Integrity

Create relationships between the tables

Set referential integrity

Page 18: Relational Databases

Queries

Allows you to ask questions about your data examples:How many employees earn more than $40,000?Which customer invoices are more than 60 days

old ?

SQL (structured query language pronounced seequel) is the underlying “how” of making queries of databases

Page 19: Relational Databases

Queries

Access does Queries by using QBE or SQL. QBE makes it easy to pick up simple queries, but becoming accomplished enough to write more complex queries takes much time and effort.

Page 20: Relational Databases

Queries

Queries are where the real POWER of adatabase lies

Relationships between tables must be properly established in order for queries to work correctly in QBE

Page 21: Relational Databases

Forms

Shows data from a table in a format that is more attractive and easier to understand

Access forms can be made to resemble paper forms that users are already familiar with

Forms are commonly used to input, display, or change data

Page 22: Relational Databases

Reports

Hard copy of output of information contained in the database

We often create reports that are the result of queries we made

Access allows you to create board room quality reports

Page 23: Relational Databases

Modules

Visual Basic for Application code that can executed at the click of a button or when a form is opened. They are useful in developing more sophisticated internal controls into an Access based information system.

Page 24: Relational Databases

REVIEW TABLE RULES

No duplicate tablesNo duplicate rows or columns in tableSequence of rows/columns doesn’t

matterEach table must have a primary keyThe primary key CANNOT be nullEach table is about ONE concept

Page 25: Relational Databases

DATABASE NORMALIZATION

Database normalization is the process of ensuring that each table contains

data about only ONE concept.

Page 26: Relational Databases

REPEATING GROUPS AND NORMALIZATION TO FIRST

NORMAL FORM (1NF)

100110021003

7/1/927/1/927/1/92

456329897

JohnMary

Al

WestEastWest

121348540

45105

$2.25$3.70$0.40

WidgetGearBolt

Invoice# Date Customer# Salesperson Region

Item# PriceDescription

INVOICES (2NF)

Invoice# Quantity

INVOICE-ITEMS (1NF)

Invoice# Date Customer# Salesperson Region Item# QuantityPriceDescription

SALES-INFORMATION

Page 27: Relational Databases

WHAT IS THE PROBLEM WITH

DESCRIPTION/PRICE?Insert anomaliesDelete anomaliesUpdate anomalies

Page 28: Relational Databases

DECOMPOSITION OF A FIRST-NORMAL-FORM

(1NF) TABLE

Item# PriceDescriptionInvoice# Quantity

INVOICE-ITEMS (1NF)

Item# PriceDescription

ITEMS (2NF)

Item#Invoice# Quantity

INVOICE-ITEMS-QTY (2NF)

You can only have a 2nd Normal Form problem if there is a composite primary Key

Page 29: Relational Databases

DATABASE NORMALIZATION

Functional dependency is key in understanding the process of

normalization. Functional dependency means that if there is only one possible value of Y for

every value of X, then Y is functionally dependent on X.

Page 30: Relational Databases

DATABASE NORMALIZATION

Think of an invoice table. Two fields would be invoice # and date. Which field is functionally dependent on the

other?

INVOICE # DATE

Date is functionally dependent on invoice number.

Page 31: Relational Databases

Functional Dependency is “good”. With functional dependency the primary key (Attribute A) determines the value of all the other non-key attributes (Attributes B,C,D,etc.)

Transitive dependency is “bad”. Transitive dependency exists if the primary key (Attribute A) determines non-key Attribute B, and Attribute B determines non-key Attribute C.

Page 32: Relational Databases

DECOMPOSITION OF A SECOND-NORMAL-FORM

(2NF) TABLE

Invoice# Date Customer# Salesperson

INVOICES (3NF)

Salesperson Region

SALESPERSON-REGION (3NF)

Invoice# Date Customer# Salesperson Region

SALES (2NF)

This is a transitive dependency which must be eliminated for 3NF

Page 33: Relational Databases

SUMMARY OF 3NF RELATIONS FOR SALES

DATABASE

Item# PriceDescription

ITEMS (3NF)

Salesperson Region

SALESPERSON-REGION (3NF)

Invoice# Date Customer# Salesperson

INVOICES (3NF)

Item# Quantity

INVOICE-ITEMS-QTY (3NF)

100110021003

7/1/927/1/927/1/92

456329897

JohnMary

Al

WestEastWest

121348540

45105

$2.25$3.70$0.40

WidgetGearBolt

Invoice#

100110021003

121348540

JohnMary

Al