Chapter 4
Chapter 4
Relational Databases
4-1
Learning Objectives
Explain the importance and advantages of databases. Describe the difference between database systems and filebased legacy systems.
4-2
Data Hierarchy
Field
Attributes about an entity
Record
Related group of fields
File
Related group of records
Database
Related group of files
Copyright 2012 Pearson Education, Inc. publishing as Prentice Hall
4-3
Data Sharing
4-4
Cross-Functional Analysis
Relationships between data from various organizational departments can be more easily combined.
4-5
Database Terminology
Database Management System (DBMS)
Interface between software applications and the data in files.
Data Dictionary
Information about the structure of the database
Field names, descriptions, uses
Copyright 2012 Pearson Education, Inc. publishing as Prentice Hall
4-6
Logical View
A Schema separates storage of data from use of the data Unnecessary to explicitly know how and where data is stored.
4-7
Schemas
Describe the logical structure of a database
Conceptual Level
Organization wide view of the data
External Level
Individual users view of the data Each view is a subschema
Internal Level
Describes how data are stored and accessed
Description of: records, definitions, addresses, and indexes
4-8
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] SAT Score --integer [2], 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
DBMS Languages
Data Definition Language (DDL)
Builds the data dictionary Creates the database Describes the subschema Specifies record or field security constraints
4-10
DBMS Languages
Data query language (DQL)
Enables the retrieval, sorting, and display of data from the database
SQL (structured query language) is the standard DQL Example:
SELECT Customer.CustName FROM Customer, Sales WHERE Customer.CustNo = Sales.CustNo AND Sales.Salesperson = Martinez
Report writer
4-11
Relational Database
Relational data model represents the conceptual and external level schemas as if data are stored in tables. Table
Each row, a tuple, contains data about one instance of an entity.
This is equivalent to a record
4-12
A Relational Table
Row (Record)
Each row contains multiple attributes describing an instance of the entity. In this case, inventory.
4-13
Attributes
Primary Key
An attribute or combination of attributes that can be used to uniquely identify a specific row (record) in a table.
Foreign Key
An attribute in one table that is a primary key in another table.
Used to link the two tables
4-14
Insert Anomaly
Unable to add a record to the database.
Delete Anomaly
Removing a record also removes unintended data from the database.
Copyright 2012 Pearson Education, Inc. publishing as Prentice Hall
4-15
Day
1 M 3 Th 11 TH 2 T
111-11-1111
111-11-1111 123-45-6789 123-45-6789
Sanders
Sanders Moore Moore
Ned
Ned Artie Artie
444-4444
444-4444 555-5555 555-5555
MGMT-3021
ANSI-1422 ACCT-3433 FIN-3213
5 W
7 F 2 T 3 Th
8:00 AM
9:00 AM 10:00 AM 11:00 AM
Student ID
Last Name
First Name
Phone No.
Course No.
Sect.
Day
Time
333-33-3333
333-33-3333 333-33-3333 111-11-1111 111-11-1111 111-11-1111 123-45-6789 123-45-6789
Simpson
Simpson Simpson Sanders Sanders Sanders Moore Moore
Alice
Alice Alice Ned Ned Ned Artie Artie
333-3333
333-3333 333-3333 444-4444 444-4444 444-4444 555-5555 555-5555
ACCT-3603
FIN-3213 MGMT-3021 ACCT-3433 MGMT-3021 ANSI-1422 ACCT-3433 FIN-3213
1 M
3 Th 11 TH 2 T 5 W 7 F 2 T 3 Th
9:00 AM
11:00 AM 12:00 PM 10:00 AM 8:00 AM 9:00 AM 10:00 AM 11:00 AM
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.
Student ID
Last Name
First Name
Phone No.
Course No.
Sect.
Day
Time
333-33-3333
333-33-3333 333-33-3333 111-11-1111 111-11-1111 111-11-1111 123-45-6789 123-45-6789
Simpson
Simpson Simpson Sanders Sanders Sanders Moore Moore
Alice
Alice Alice Ned Ned Ned Artie Artie
333-3333
333-3333 333-3333 444-4444 444-4444 444-4444 555-5555 555-5555
ACCT-3603
FIN-3213 MGMT-3021 ACCT-3433 MGMT-3021 ANSI-1422 ACCT-3433 FIN-3213
1 M
3 Th 11 TH 2 T 5 W 7 F 2 T 3 Th
9:00 AM
11:00 AM 12:00 PM 10:00 AM 8:00 AM 9:00 AM 10:00 AM 11:00 AM
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.
Student ID
Last Name
First Name
Phone No.
Course No.
Sect.
Day
Time
333-33-3333
333-33-3333 333-33-3333 111-11-1111 111-11-1111 111-11-1111 123-45-6789 123-45-6789
Simpson
Simpson Simpson Sanders Sanders Sanders Moore Moore
Alice
Alice Alice Ned Ned Ned Artie Artie
333-3333
333-3333 333-3333 444-4444 444-4444 444-4444 555-5555 555-5555
ACCT-3603
FIN-3213 MGMT-3021 ACCT-3433 MGMT-3021 ANSI-1422 ACCT-3433 FIN-3213
1 M
3 Th 11 TH 2 T 5 W 7 F 2 T 3 Th
9:00 AM
11:00 AM 12:00 PM 10:00 AM 8:00 AM 9:00 AM 10:00 AM 11:00 AM
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.
4-20
4-21