31
Chapter 5 Database Processing

Chapter 5 Database Processing. Neil uses software to query a database, but it has about 25 standard queries that don’t give him all he needs. He imports

Embed Size (px)

Citation preview

Chapter 5

Database Processing

Neil uses software to query a database, but it has about 25 standard queries that don’t give him all he needs.He imports data from database into Excel where he moves, sorts, sums and averages data until he gets information he wants.

It’s a pain, but it works.

This Could Happen to You: “The Database Shows . . .”

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

FlexTime video clip

5-2

Q1 What is the purpose of a database?

Q2 What does a database contain?

Q3 What is a DBMS, and what does it do?

Q4 What is a database application?

Q5 What is the difference between an enterprise DBMS and a personal DBMS?

How does the knowledge in this chapter help FlexTime and you?

Study Questions

5-3Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Purpose: To organize and keep track of things

Spreadsheets

•Keep track of only a single themeExample: Student test scores in a course

Databases

•Allow keeping track of multiple themesExamples: Student grades, office visits, student email

Q1: What Is the Purpose of a Database?

5-4Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

A List of Student Grades, Presented in a Spreadsheet

5-5Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Student Data Shown in a Form from a Database

5-6Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Q2: What Does a Database Contain?

5-7Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Table or file: A group of records

Hierarchy of Data Elements

5-8Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Components of a Database

5-9Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Metadata: Describes structure of database (tables, relationships, primary key, etc.) and its data such as data type (text, number, date), size, default, format, etc.

Relational database

Database has multiple tables (one for each theme)

Values in one table may relate to records in other tables

Primary or Unique key

Field(s) that uniquely identify a record in a table

Each table must have a key

Foreign key

A non-primary key in one table that is related to a primary key of a different table

Relationships Among Records

5-10Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

• A column or group of columns that identifies a unique row in a table

• Student Number is key of Student table

• Every table must have a key• Sometimes more than one column

is needed to form a unique identifier Example: key of City table, would be a combination of City and State columns.

• Email_Num is key of Email Table• VisitID is key of Office_Visit Table

Key

Special Terms

1-11Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

• Relationships among tables are created by using foreign keys

Relational database

s

• Formal term for a tableRelation

More Special Terms

1-12Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

5-13Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Figure 5-6

Relationships Among Records in Three Tables

Database: Self-describing collection of integrated records

Metadata• Data that describes

data • Makes databases

more useful• Makes databases

easier to use

Describes data by: • Data type: text,

number, date, etc.• Field name• Field properties

Metadata

5-14Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Sample Metadata in Access

5-15Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Database Management System (DBMS):Database Management System (DBMS):―Program that creates, processes, and administers

databases―Examples: DB2, Microsoft Access, SQL Server,

Oracle, MySQL (open-source DBMS)

Q3: What Is a DBMS and What Does It Q3: What Is a DBMS and What Does It Do?Do?

5-16Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

DatabaseCollection of tables, relationshi

ps, and metadata

Components of a Database Application System

5-17Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Creating the Database and Its Structure: Adding “Response?” Field to a Table

5-18Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

• Read, Insert, Modify, and Delete data

Four DBMS operations

• International standard language for processing databases

Structured Query

Language (SQL)

INSERT INTO Student([Student Number], [Student Name], HW1, HW2, MidTerm)VALUES (1000, ‘Franklin, Benjamin’, 90, 95, 100)

Example SQL statement

Processing the Database: SQLProcessing the Database: SQL

5-19Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Assignment: View this in your Access assignment as you create a query

DBMS security features to set up user accounts, passwords, permissions, processing limits

Permissions—setting data access rights for specific users or groups of users. We typically do not do it in Access database, but in network database like SQL ServerDatabase backup and replication, adding structures, removing unneeded data

Administering the Database

5-20Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Q4: What Is a Database Application?Q4: What Is a Database Application?

5-21Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Forms

Reports

Queries

Forms, Reports, and Queries

5-22Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Example of a Database Query and Query Result

5-23Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Query form

Query result

Report

Processing logic for a specific

business need

Internet database processing to:

Connect web server and database

Respond to events

Read, insert, modify,

delete data

Database Application Programs

5-24Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Four Database Application Programs Four Database Application Programs Running on a Web Server Via InternetRunning on a Web Server Via Internet

5-25Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Lost-update problemOccurs when two or more transactions select same record at

same time, then update it based on values first received. Each transaction is independent. Last update overwrites updates previously made by others.

Multiuser Processing Considerations

5-26Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

10-5 = 5 10-3 = 75, 7 or 3?

1.Process A reads customer record from file containing customer’s account balance.

1

2.Process B reads same record from same file now has its own copy.

2

3.Process A updates account balance in its copy of customer record and writes record to file.

3

4.Process B has original stale value for account balance. Updates customer’s phone number and writes customer record to file.

4

5.Process B writes stale account balance value to file, causing changes made by Process A to be lost.

5

Multi-User Processing Problem: Multi-User Processing Problem: Lost-Lost-update problemupdate problem

1-27Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Locking

• Prevents another user or process to change a record currently being used by another user or process.

• Gets only a Read-only copyGets only a Read-only copy.

Preventing Lost Update ProblemPreventing Lost Update Problem

5-28Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Enterprise DBMSEnterprise DBMS• Processes large

organizational and workgroup databases

• Supports many users (thousands plus)

• Examples: DB2, SQL Server, Oracle, MySQL

Enterprise DBMSEnterprise DBMS• Processes large

organizational and workgroup databases

• Supports many users (thousands plus)

• Examples: DB2, SQL Server, Oracle, MySQL

Personal DBMSPersonal DBMS• Designed for smaller,

simpler database applications

• Supports fewer than 100 users (mostly 1–10 users)

• Examples: Access, dBase, FoxPro, R-Base

Personal DBMSPersonal DBMS• Designed for smaller,

simpler database applications

• Supports fewer than 100 users (mostly 1–10 users)

• Examples: Access, dBase, FoxPro, R-Base

Q5: What Is the Difference Between Q5: What Is the Difference Between an Enterprise DBMS and a an Enterprise DBMS and a Personal DBMS?Personal DBMS?

5-29Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Personal Database SystemPersonal Database System

5-30Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Personal AssignmentPersonal Assignment

5-31Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall

Create a Microsoft Access database that will contain Create a Microsoft Access database that will contain three to four tables such as:three to four tables such as:

•CustomerCustomer•ProductsProducts•OrdersOrders•BillingBilling

•Create a Form through which Customers can make Create a Form through which Customers can make ordersorders•Create a Query and then a Report of recent Orders by Create a Query and then a Report of recent Orders by CustomersCustomers