Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 38

Relational Databases

Chapter 4

Copyright © 2015 Pearson Education, Inc.


4-1
Learning Objectives
• Explain the importance and advantages of databases, as well as the
difference between database and file-based legacy systems.

• Explain the difference between logical and physical views of a


database.

• Explain fundamental concepts of database systems such as DBMS,


schemas, the data dictionary, and DBMS languages.

• Describe what a relational database is and how it organizes data.

• Create a set of well-structured tables to properly store data in a


relational database.

• Perform simple queries using the Microsoft Access database.

Copyright © 2015 Pearson Education, Inc.


4-2
What Is a Database?
• Efficiently and centrally coordinates information for a
related group of files
• A file is a related group of records
• A record is a related group of fields
• A field is a specific attribute of
interest for the entity (record)

Basic Elements of
Data Hierarchy

Copyright © 2015 Pearson Education, Inc.


4-3
Databases and Files
Database Management System (DBMS)
• The program that manages and controls the data and the
interfaces between the data and the application programs
that use the data stored in the database.

Database System
• The database, the DBMS, and the application programs that
access the database through the DBMS.

Database Administrator (DBA)


• The person responsible for coordinating, controlling, and
managing the database.
Copyright © 2015 Pearson Education, Inc.
4-4
Using Data Warehouses for
Business Intelligence
Data Warehouse
• One or more very large databases containing both detailed
and summarized data for a number of years that is used for
analysis rather than transaction processing.
• Measured in petabytes (1,000 terabytes or 1 million
gigabytes)

Transaction Processing Databases Data Warehouse


Minimize redundancy; Maximize query efficiency
Maximize efficiency

Copyright © 2015 Pearson Education, Inc.


4-5
Using Data Warehouses for
Business Intelligence
Analyzing large amounts of data for strategic decision making is
often referred to as business intelligence (BI).
Online Analytical Processing
Data Mining
(OLAP)
• Using queries to investigate • Using sophisticated statistical
hypothesized relationships among analysis, including artificial
data. intelligence (AI) techniques to
• Example: A manager may analyze “discover” unhypothesized
supplier purchases for the last 3 relationships in the data.
years, followed by additional • Example: A credit card company
queries that “drill down” to lower uses data mining to identify usage
levels by grouping purchases by patterns indicative of fraud.
item number and by fiscal period.

Copyright © 2015 Pearson Education, Inc.


4-6
Learning Check
Column A Column B
1. DBMS A. Analyzing large amounts of data for strategic decision making

2. Database System B. The person responsible for coordinating, controlling,


and managing the database.
3. DBA C. Using queries to investigate hypothesized relationships among data.

4. Data Warehouse D. The program that manages and controls the data and the
interfaces between the data and the application programs that
use the data stored in the database.

5. Business Intelligence E. One or more very large databases containing both


detailed and summarized that is used for analysis
6. OLAP F. Using sophisticated statistical analysis, including artificial
intelligence (AI) techniques to “discover” unhypothesized
relationships in the data.

7. Data Mining G. Efficiently and centrally coordinates information for


a related group of files
8. Database H. The database, the DBMS, and the application
programs that access the database through the DBMS.
Copyright © 2015 Pearson Education, Inc.
4-7
Advantages of Databases
• Data is integrated and easy to share
• Minimize data redundancy
• Data is independent of the programs that use the
data
• Data is easily accessed for reporting and cross-
functional analysis

Copyright © 2015 Pearson Education, Inc.


4-8
Relational Database
Relational Database
• It is a collective set of multiple data sets organized by
tables, records, and columns.
• It establishes a well-defined relationship between
database tables.

Structured Query Language (SQL)


• It is a standard user application that provides an easy
programming interface for database interaction.

Copyright © 2015 Pearson Education, Inc.


4-9
Relational Database
One or more data or record characteristics relate to one or
many records to form functional dependencies/relationship:
• One to One: One table record relates to another record in
another table.
• One to Many/Many to One: One table record relates to
many records in another table.
• Many to Many: More than one table record relates to
more than one record in another table.

Copyright © 2015 Pearson Education, Inc.


4-10
Learning Check
• Give an example of one-to-one relationship.
• Give an example of one-to-many/many-to-one relationship.

Copyright © 2015 Pearson Education, Inc.


4-11
Data Processing Cycle

Copyright © 2015 Pearson Education, Inc.


4-12
Computer-Based Storage

Data is stored in master files or transaction files.

Copyright © 2015 Pearson Education, Inc.


4-13
Database Concepts
File
• A set of logically related records.
Master File
• A permanent file of records that stores cumulative data about an
organization.
Transaction File
• A file that contains the individual business transactions that occur during a
specific fiscal period.
Database
• A set of interrelated, centrally controlled data files that are stored.

Copyright © 2015 Pearson Education, Inc.


4-14
Database Concepts
Entity
• The item about which information is stored in a record.
Attributes
• The properties, identifying numbers, and characteristics of interest of an
entity that is stored in a database.
Field
• The portion of a data record where the data value for a particular attribute
is stored.
Record
• A set of fields whose data values describe specific attributes of an entity.
Data Value
• The actual value stored in a field. It describes a particular attribute of an
entity.
Copyright © 2015 Pearson Education, Inc.
4-15
Learning Check
• Identify the entity, attributes, field, record, and
data value for the Employee table below.

Copyright © 2015 Pearson Education, Inc.


4-16
Learning Check
• Identify the entity, attributes, field, record, and data
value for the Purchases and Product tables below.

Copyright © 2015 Pearson Education, Inc.


4-17
Relational Data Tables

Copyright © 2015 Pearson Education, Inc.


4-18
Relational Data Tables

Primary Keys

Foreign Key (Customer # is a Foreign


key in the Sales Table because it is a
Primary key that uniquely identifies
Customers in the Customer Table).
Because of this, the Sales Table can relate
to the Customer Table (see red arrow
above).
Copyright © 2015 Pearson Education, Inc.
4-19
Types of Attributes
Primary Key
• It is the database attribute, or combination of attributes,
that uniquely identifies a specific row in a table.

Foreign Key
• It is an attribute in a table that is also a primary key in
another table and used to link the two tables.

Copyright © 2015 Pearson Education, Inc.


4-20
• Download the S&S In-Chapter Database
(get from instructor)

Copyright © 2015 Pearson Education, Inc.


Query 1: What are the invoice numbers of all sales made
to D. Ainge, and who was the salesperson for each sale?

• Click the “Query Design” button and select


Customer and Sales tables
• Double Click on Sales Invoice #, Salesperson,
and Customer Name.
• Enter “D. Ainge” in the criteria line of the
Customer Name column.
• Run the query by clicking on the red !
(exclamation) mark on the Query Tools Design
ribbon.
Copyright © 2015 Pearson Education, Inc.
4-18
Query 1: What are the invoice numbers of all sales made
to D. Ainge, and who was the salesperson for each sale?

• To assign the query a name, save it by selecting


File from the Access menu, the Save Object As,
and then enter “Ainge Sales”.
• In the first line of the Save As window, make
sure that the Object select box is set to “Query”
and then click OK.

Copyright © 2015 Pearson Education, Inc.


4-19
Copyright © 2015 Pearson Education, Inc.
4-20
Query #1

• What are the invoice numbers of all sales made to


F. Roberts, and who was the salesperson for each sale?

Query Result:

Copyright © 2015 Pearson Education, Inc.


4-32
Query 2: How many televisions were sold in October 2018?

• Click the “Query Design” button and select Sales,


Inventory, and Sales-Inventory.
• Double Click on Date, Inventory Description,
and Quantity.
• Since we want the quantity of television sold in
October, we add the criteria “Between
#10/1/2018# And #10/31/2018#” to the Date
field and “Television” to the Description field.

Copyright © 2015 Pearson Education, Inc.


4-21
Query 2: How many televisions were sold in October 2018?

• Since we are only looking for total television


sales in October, uncheck the “Show” box in the
Date and Description columns.
• To generate total sales, click the “Totals” button
in the Query Tools Design ribbon.
• A new row, labeled Total, appears. Click on the
Totals line in the Quantity column.
• Click on the down-arrow symbol, and select Sum
from the drop-down menu that appears.
Copyright © 2015 Pearson Education, Inc.
4-22
Copyright © 2015 Pearson Education, Inc.
4-23
Query 3: What are the names and addresses of customers
buying televisions in October 2018?

• Click the “Query Design” button and select all


tables.
• Double Click on Date (to select October sales),
Description (to select televisions), and Customer
Name, Street, City, and State (the information
requested).
• The Data and Description data do not need to be
displayed, so the boxes in the Show line are
unchecked.
Copyright © 2015 Pearson Education, Inc.
4-24
Copyright © 2015 Pearson Education, Inc.
4-25
Query #2

• How many ranges were sold in October 2018?

Query Result:

Copyright © 2015 Pearson Education, Inc.


4-32
Query 4: What are the sales invoice numbers, dates, and
invoice totals for October 2018 sales, arranged in
descending order by sale amount?

• Since the database does not contain an Invoice


Total column, it is calculated by multiplying the
unit price by the quantity for each sale.
Invoice Total= Quantity (S-I) x Unit Price (I)
• For item 20, we multiply the quantity (3) by the
Unit Price (699), producing 2,097. The same
calculation is made for items 10 and 30.
• Finally, the sum of the three time totals is equals
to the Invoice Total.
Copyright © 2015 Pearson Education, Inc.
4-26
Query 4: What are the sales invoice numbers, dates, and
invoice totals for October 2018 We sales, arranged in
descending order by sale amount?

• Query 4 requires the Sales table (Date, Sales


Invoice #), Sales-Inventory table (Quantity), and
the Inventory table (Unit Price).
• We need to display the following columns:
▫ Sales Invoice # (Sales table)
▫ Date (Sales table)
▫ Invoice Total (Calculated)
The other fields, Quantity and Unit Price, are
used in the Invoice Total calculations.
Copyright © 2015 Pearson Education, Inc.
4-27
Query 4: What are the sales invoice numbers, dates, and
invoice totals for October 2018 We sales, arranged in
descending order by sale amount?

• To calculate Invoice Total, type “Invoice Total:”


in the first blank Field cell, right-click in the cell,
and select Build from the pop-up menu that
appears. An Expression Builder window appears
where the formula to calculate the Invoice Total
is entered by typing “Sum( )”.
• Between the parentheses, click on the + sign in
front of the S&S In-Chapter Database folder in
the Expressions Elements box.
Copyright © 2015 Pearson Education, Inc.
4-28
Query 4: What are the sales invoice numbers, dates, and
invoice totals for October 2018 We sales, arranged in
descending order by sale amount?

• Then, clicking on the + sign in the Tables folder


causes the four database tables to appear.
• Click on the Sales-Inventory table, then, double
click on Quantity to put in the expression.
• To multiply Quantity by Unit Price, type * and
select the Inventory table and Unit Price field.
• To enter the expression into the Select Query
window, click on OK.

Copyright © 2015 Pearson Education, Inc.


4-29
Query 4: What are the sales invoice numbers, dates, and
invoice totals for October 2018 We sales, arranged in
descending order by sale amount?

• To complete Query 4, click the “Totals” button in


the Query Tools Design ribbon.
• Click on the down arrow in the Total row of the
Invoice Totals column, and select Expression
from the pop-up menu.
• In the same column, click on the down arrow in
the Sort row, and select Descending so that the
answer is shown in descending Invoice Total
order.
Copyright © 2015 Pearson Education, Inc.
4-30
Copyright © 2015 Pearson Education, Inc.
4-31
Query #3

• What are the sales invoice numbers, dates, and invoice


totals for November 2018 sales, arranged in ascending
order by sale amount?

Query Result:

Copyright © 2015 Pearson Education, Inc.


4-32

You might also like