AIS Relational Databases
AIS Relational Databases
Chapter 4
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.
Copyright Pearson Education Limited 2015.
4-2
INTRODUCTION
Relational databases underlie most modern
integrated AISs.
They are the most popular type of database used
for transaction processing.
In this chapter, well define the concept of a
database.
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)
4-3
Last Name
First Name
Phone
Number
Birth Date
333-33-3333
Simpson
Alice
333-3333
10/11/84
111-11-1111
Sanders
Ned
444-4444
11/24/86
123-45-6789
Moore
Artie
555-5555
04/20/85
Last Name
First Name
Phone
Number
Birth Date
333-33-3333
Simpson
Alice
333-3333
10/11/84
111-11-1111
Sanders
Ned
444-4444
11/24/86
123-45-6789
Moore
Artie
555-5555
04/20/85
Last Name
First Name
Phone
Number
Birth Date
333-33-3333
Simpson
Alice
333-3333
10/11/84
111-11-1111
Sanders
Ned
444-4444
11/24/86
123-45-6789
Moore
Artie
555-5555
04/20/85
Last Name
First Name
Phone
Number
Birth Date
333-33-3333
Simpson
Alice
333-3333
10/11/84
111-11-1111
Sanders
Ned
444-4444
11/24/86
123-45-6789
Moore
Artie
555-5555
04/20/85
Student
File
Class
File
Advisor
File
Master File 2
Fact A
Fact D
Fact F
Enrollment
Program
Financial Aid
Program
Master File 1
Grades
Fact A
Program
Fact B
FactFPearson Education Limited 2015.
Copyright
Database
Fact A Fact B
Fact C Fact D
Fact E Fact F
Database
Management
System
Enrollment
Program
Financial Aid
Program
Grades
Program
Database
Management
System
Enrollment
Program
Financial Aid
Program
Grades
Program
Database
Fact A Fact B
Fact C Fact D
Fact E Fact F
Database
Management
System
Enrollment
Program
Financial Aid
Program
Grades
Program
Database
Management
System
Enrollment
Program
Financial Aid
Program
Grades
Program
The person
responsible for the
database is the
database
administrator.
As technology
improves, many large
companies are
developing very large
databases called data
warehouses.
Data integration
Data sharing
Reporting flexibility
Minimal data redundancy and inconsistencies
Data independence
Central management of data
Cross-functional analysis
DATABASE SYSTEMS
Logical and physical views of data
In file-oriented systems, programmers must know
the physical location and layout of records used by
a program.
They must reference the location, length, and format
of every field they utilize.
When data is used from several files, this process
becomes more complex.
DATABASE SYSTEMS
Database systems overcome this problem by
separating the storage and use of data elements.
Two separate views of the data are provided:
Logical view
Physical view
Logical ViewUser B
Logical ViewUser A
Scholarship Distribution
Enrollment by Class
Sr.
33%
Fr.
5%
Soph.
24%
Jr.
38%
DBMS
Operating
System
Database
Copyright Pearson Education Limited 2015.
Logical ViewUser B
Logical ViewUser A
Scholarship Distribution
Enrollment by Class
Sr.
33%
Fr.
5%
Soph.
24%
Jr.
38%
DBMS
Operating
System
Database
Copyright Pearson Education Limited 2015.
DATABASE SYSTEMS
The DBMS handles the link between the physical
and logical views of the data.
Allows the user to access, query, and update data
without reference to how or where it is physically
stored.
The user only needs to define the logical data
requirements.
DATABASE SYSTEMS
Separating the logical and physical views of data
also means users can change their
conceptualizations of the data relationships
without making changes in the physical storage.
The database administrator can also change the
physical storage of the data without affecting
users or application programs.
DATABASE SYSTEMS
Schemas
A schema describes the logical and physical
structures of a database.
There are three levels of schema.
Conceptual level
The organization-wide view of the entire
databasei.e., the big picture.
Lists all data elements and the relationships
between them.
DATABASE SYSTEMS
Schemas
A schema describes the logical and physical
structures of a database.
There are three levels of schema.
Conceptual level
External level
A set of individual user views of portions of the
database, i.e., how each user sees the portion of
the system with which he interacts.
These individual views are referred to as
subschema.
Copyright Pearson Education Limited 2015.
DATABASE SYSTEMS
Schemas
A schema describes the logical and physical
structures of a database.
There are three levels of schema.
Conceptual level
A low-level view of the database.
External level
It describes how the data are actually
Internal level
stored and accessed including:
Record layouts
Definitions
Addresses
Indexes
Subschema--User A
Subschema--User B
Subschema--User C
Smith . . . A
Jones . . . B
Arnold . . .D
Classes
Enroll
Student
Cash
Receipt
Mapping conceptual-level items to internal-level descriptions
Student Record
Student No.
--character [9]
Student Name --character [26]
Copyright
Pearson
Education
2015.
SAT Score
--integer
[2],Limited
non-null,
index=itemx
Class Record
Class Name --character [9]
Dept No.
--integer [4], non-null, index=itemx
Course No.
--integer [4], non-null, index=itemx
Subschema--User A
Subschema--User B
Subschema--User C
Smith . . . A
Jones . . . B
Arnold . . .D
Classes
Enroll
Cash
Receipt
Student
The
bidirectional
arrows
represent
mappings
between the
schema.
Class Record
Class Name --character [9]
Dept No.
--integer [4], non-null, index=itemx
Course No.
--integer [4], non-null, index=itemx
DATABASE SYSTEMS
The DBMS uses the mappings to translate a
request by a user or program for data (expressed
in logical names and relationships) into the
indexes and addresses needed to physically
access the data.
DATABASE SYSTEMS
Accountants are frequently involved in
developing conceptual- and external-level
schema.
An employees access to data should be limited
to the subschema of data that is relevant to the
performance of his job.
4-5
Database Design
To design a database, you need to have a
conceptual view of the entire database. The
conceptual view illustrates the different files and
relationships between the files.
The data dictionary is a blueprint of the
structure of the database and includes data
elements, field types, programs that use the data
element, outputs, and so on.
Copyright Pearson Education Limited 2015.
4-6
DATABASE SYSTEMS
The data dictionary
A key component of a DBMS is the data
dictionary.
Contains information about the data elements in the
database such as meaning, relationships to other
data, origin, usage, and format.
For each data element, there is a corresponding
record in the data dictionary describing that
element.
DATABASE SYSTEMS
Information provided for each element includes:
DATABASE SYSTEMS
Accountants should participate in the
development of the data dictionary because they
have a good understanding of the data elements
in a business organization, as well as where
those elements originate and how they are used.
DATABASE SYSTEMS
The DBMS usually maintains the data
dictionary.
Outputs include:
DATABASE SYSTEMS
DBMS Languages
Every DBMS must provide a means of
performing the three basic functions of:
Creating a database
Changing a database
Querying a database
DATABASE SYSTEMS
Creating a database:
The set of commands used to create the database
is known as data definition language (DDL).
DDL is used to:
Build the data dictionary
Initialize or create the database
Describe the logical views for each individual user or
programmer
Specify any limitations or constraints on security
imposed on database records or fields
DATABASE SYSTEMS
Changing a database
The set of commands used to change the database
is known as data manipulation language
(DML). DML is used for maintaining the data
including:
Updating data
Inserting data
Deleting portions of the database
DATABASE SYSTEMS
Querying a database:
The set of commands used to query the database is
known as data query language (DQL). DQL is
used to interrogate the database, including:
Retrieving records
Sorting records
Ordering records
Presenting subsets of the database
DATABASE SYSTEMS
Report Writer
Many DBMS packages also include a report writer,
a language that simplifies the creation of reports.
Users typically specify:
What elements they want printed
How the report should be formatted
DATABASE SYSTEMS
Users typically have access to both DQL and
report writer.
Access to DDL and DML are typically restricted
to employees with administrative and
programming responsibilities.
RELATIONAL DATABASES
A DBMS is characterized by the type of logical
data model on which it is based.
A data model is an abstract representation of
the contents of a database.
Most new DBMSs are called relational
databases because they use the relational model
developed by E. F. Codd in 1970.
RELATIONAL DATABASES
The relational data model represents
everything in the database as being stored in the
forms of tables (aka, relations).
This model only describes how the data appear
in the conceptual- and external-level schemas.
The data are physically stored according to the
description in the internal-level schema.
Each row is
called a tuple,
which rhymes
with couple.
Each row
contains data
about a specific
occurrence of
the type of entity
in the table.
Each column in
a table contains
information
about a specific
attribute of the
entity.
STUDENTS
Student ID
Last Name
First
Name
Phone No.
Advisor
No.
333-33-3333
Simpson
Alice
333-3333
1418
111-11-1111
Sanders
Ned
444-4444
1418
123-45-6789
Moore
Artie
555-5555
1503
ADVISORS
Advisor No.
Last Name
First Name
Office No.
1418
Howard
Glen
420
1419
Melton
Amy
316
1503
Zhang
Xi
202
1506
Radowski
J.D.
203
STUDENTS
Student ID
Last Name
First
Name
Phone No.
Advisor
No.
333-33-3333
Simpson
Alice
333-3333
1418
111-11-1111
Sanders
Ned
444-4444
1418
123-45-6789
Moore
Artie
555-5555
1503
ADVISORS
Advisor No.
Last Name
First Name
Office No.
1418
Howard
Glen
420
1419
Melton
Amy
316
1503
Zhang
Xi
202
1506
Radowski
J.D.
203
STUDENTS
Student ID
Last Name
First
Name
Phone No.
Advisor
No.
333-33-3333
Simpson
Alice
333-3333
1418
111-11-1111
Sanders
Ned
444-4444
1418
123-45-6789
Moore
Artie
555-5555
1503
ADVISORS
Advisor No.
Last Name
First Name
Office No.
1418
Howard
Glen
420
1419
Melton
Amy
316
1503
Zhang
Xi
202
1506
Radowski
J.D.
203
RELATIONAL DATABASES
Alternatives for storing data
One possible alternate approach would be to store
all data in one uniform table.
For example, instead of separate tables for
students and classes, we could store all data in one
table and have a separate line for each student x
class combination.
Student ID
Last
Name
First
Name
Phone No.
333-33-3333
Simpson
Alice
333-3333
ACCT-3603
1 M
9:00 AM
333-33-3333
Simpson
Alice
333-3333
FIN-3213
3 Th
11:00 AM
333-33-3333
Simpson
Alice
333-3333
MGMT-3021
11 Th
12:00 PM
111-11-1111
Sanders
Ned
444-4444
ACCT-3433
2 T
10:00 AM
111-11-1111
Sanders
Ned
444-4444
MGMT-3021
5 W
8:00 AM
111-11-1111
Sanders
Ned
444-4444
ANSI-1422
7 F
9:00 AM
123-45-6789
Moore
Artie
555-5555
ACCT-3433
2 T
10:00 AM
123-45-6789
Moore
Artie
555-5555
FIN-3213
3 Th
11:00 AM
Course No.
Section
Day
Time
Student ID
Last
Name
First
Name
Phone No.
333-33-3333
Simpson
Alice
333-3333
ACCT-3603
1 M
9:00 AM
333-33-3333
Simpson
Alice
333-3333
FIN-3213
3 Th
11:00 AM
333-33-3333
Simpson
Alice
333-3333
MGMT-3021
11 Th
12:00 PM
111-11-1111
Sanders
Ned
444-4444
ACCT-3433
2 T
10:00 AM
111-11-1111
Sanders
Ned
444-4444
MGMT-3021
5 W
8:00 AM
111-11-1111
Sanders
Ned
444-4444
ANSI-1422
7 F
9:00 AM
123-45-6789
Moore
Artie
555-5555
ACCT-3433
2 T
10:00 AM
123-45-6789
Moore
Artie
555-5555
FIN-3213
3 Th
11:00 AM
Course No.
Section
Day
Time
Suppose Alice Simpson changes her phone number. You need to make
the change in three places. If you fail to change it in all three places or
change it incorrectly in one place, then the records for Alice will be
inconsistent.
This problem is referred to as an update anomaly.
Copyright Pearson Education Limited 2015.
Student ID
Last
Name
First
Name
Phone No.
333-33-3333
Simpson
Alice
333-3333
ACCT-3603
1 M
9:00 AM
333-33-3333
Simpson
Alice
333-3333
FIN-3213
3 Th
11:00 AM
333-33-3333
Simpson
Alice
333-3333
MGMT-3021
11 Th
12:00 PM
111-11-1111
Sanders
Ned
444-4444
ACCT-3433
2 T
10:00 AM
111-11-1111
Sanders
Ned
444-4444
MGMT-3021
5 W
8:00 AM
111-11-1111
Sanders
Ned
444-4444
ANSI-1422
7 F
9:00 AM
123-45-6789
Moore
Artie
555-5555
ACCT-3433
2 T
10:00 AM
123-45-6789
Moore
Artie
555-5555
FIN-3213
3 Th
11:00 AM
Course No.
Section
Day
Time
What happens if you have a new student to add, but he hasnt signed up
for any courses yet?
Or what if there is a new class to add, but there are no students enrolled
in it yet? In either case, the record will be partially blank.
This problem is referred to as an insert anomaly.
Copyright Pearson Education Limited 2015.
Student ID
Last
Name
First
Name
Phone No.
333-33-3333
Simpson
Alice
333-3333
ACCT-3603
1 M
9:00 AM
333-33-3333
Simpson
Alice
333-3333
FIN-3213
3 Th
11:00 AM
333-33-3333
Simpson
Alice
333-3333
MGMT-3021
11 Th
12:00 PM
111-11-1111
Sanders
Ned
444-4444
ACCT-3433
2 T
10:00 AM
111-11-1111
Sanders
Ned
444-4444
MGMT-3021
5 W
8:00 AM
111-11-1111
Sanders
Ned
444-4444
ANSI-1422
7 F
9:00 AM
123-45-6789
Moore
Artie
555-5555
ACCT-3433
2 T
10:00 AM
123-45-6789
Moore
Artie
555-5555
FIN-3213
3 Th
11:00 AM
Course No.
Section
Day
Time
If Ned withdraws from all his classes and you eliminate all three of his
rows from the table, then you will no longer have a record of Ned. If Ned
is planning to take classes next semester, then you probably didnt
really want to delete all records of him.
This problem is referred to as a delete anomaly.
Copyright Pearson Education Limited 2015.
RELATIONAL DATABASES
Alternatives for storing data
Another possible approach would be to store each
student in one row of the table and create multiple
columns to accommodate each class that he is
taking.
Student ID
Last
Name
First
Name
Phone
No.
333-33-3333
Simpson
Alice
333-3333
ACCT-3603
FIN-3213
MGMT-3021
111-11-1111
Sanders
Ned
444-4444
ACCT-3433
MGMT-3021
ANSI-1422
123-45-6789
Moore
Artie
555-5555
ACCT-3433
FIN-3213
Class 1
Class 2
Class 3
Class 4
RELATIONAL DATABASES
Basic requirements of a relational database
Every column in a row must be single valued.
In other words, every cell can have one and only one
value.
In the student table, you couldnt have an attribute
named Phone Number if a student could have
multiple phone numbers.
There might be an attribute named local phone
number and an attribute named permanent phone
number.
You could not have an attribute named Class in the
student table, because a student could take multiple
classes.
Copyright Pearson Education Limited 2015.
RELATIONAL DATABASES
Basic requirements of a relational
database
The primary key cannot be null.
The primary key uniquely identifies a specific row in
the table, so it cannot be null, and it must be unique
for every record.
This rule is referred to as the entity integrity
rule.
RELATIONAL DATABASES
Basic requirements of a relational
database
A foreign key must either be null or correspond to
the value of a primary key in another table.
This rule is referred to as the referential
integrity rule.
The rule is necessary because foreign keys are used
to link rows in one table to rows in another table.
STUDENTS
Student ID
Last Name
First
Name
Phone No.
Advisor
No.
333-33-3333
Simpson
Alice
333-3333
1418
111-11-1111
Sanders
Ned
444-4444
1418
123-45-6789
Moore
Artie
555-5555
1503
ADVISORS
Advisor No.
Last Name
First Name
Office No.
1418
Howard
Glen
420
1419
Melton
Amy
316
1503
Zhang
Xi
202
1506
Radowski
J.D.
203
RELATIONAL DATABASES
Basic requirements of a relational
database
All non-key attributes in a table should describe a
characteristic of the object identified by the
primary key.
Could nationality be a non-key attribute in the
student table?
Could advisors nationality be a non-key
attribute in the student table?
RELATIONAL DATABASES
The preceding four constraints produce a wellstructured (normalized) database in which:
Data are consistent.
Redundancy is minimized and controlled.
RELATIONAL DATABASES
An important feature is that data about various things of
interest (entities) are stored in separate tables.
Add a
student
here.
Leaves no
blank
spaces.
RELATIONAL DATABASES
Deletion of a class for a student would cause the
elimination of one record in the student x class
table.
The student still exists in the student table.
The class still exists in the class table.
Avoids the delete anomaly.
Ned still
exists in
the student
table.
4-10
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).
4-11
4-12
4-13
Key Terms
Database
Database management system
(DBMS)
Database system
Database administrator (DBA)
Data warehouse
Business intelligence
Online analytical processing
(OLAP)
Data mining
Record layout
Logical view
Physical view
Schema
Conceptual-level schema
Copyright Pearson Education Limited 2015.
External-level schema
Subschema
Internal-level schema
Data dictionary
Data definition language
(DDL)
Data manipulation language
(DML)
Data query language (DQL)
Report writer
Data model
Relational data model
Tuple
Primary key
Foreign key
4-17
Update anomaly
Insert anomaly
Delete anomaly
Relational database
Entity integrity rule
Referential integrity rule
Normalization
Semantic data modeling
4-18