Download presentation
Presentation is loading. Please wait.
1
File and Database Processing
Chapter 9 File and Database Processing Programming Logic for Business Laura Saret EdD Copyright 2001 Laura Saret
2
Chapter Outline What Are File Organization and Access?
What Are the Various Types of Files Used by Business Systems? Example: Sequential File Merging Program Example: Sequential File Matching Program Example: Sequential File Update Program How Are Direct and Indexed Files Processed? What Are Pointers, Chains, and Rings? Why Use Databases Instead of Traditional Files? What Are the Models for Database Organization? How Do You Select a File or Database Organization?
3
Chapter Objectives After completing this chapter you should be able to.… Explain the differences between sequential and direct (random) access and give examples of applications that use each. Describe the various types of business files including master files, transaction files, table files, temporary files, log files, mirror files, and archive files. Describe the two ways of organizing data on sequential files. Discuss the purposes of sequential file merging, matching, and update programs, as well as construct the logic for such programs.
4
Chapter Objectives (continued)
After completing this chapter you should be able to.… Explain the advantages and disadvantages of nonsequential processing. Explain methods for backup. Describe how records are accessed nonsequentially by their addresses, including the purposes of randomizing routines, pointers, chains, and rings. Explain how indexed files are organized and accessed. Describe the issues involved in selecting a file organization.
5
Chapter Objectives (continued)
After completing this chapter you should be able to.… Understand the data redundancy, integrity, and independence issues involved with traditional file organization. Explain the purpose of a database management system. Explain how data are organized on databases using the hierarchical, network, and relational models as well as how object-oriented databases differ from traditional databases. Discuss selecting a particular file or database organization.
6
File Organization Describes how records are stored within a file
Four organization methods Serial Sequential Direct (relative) Indexed All other organization schemes are variations of or combinations of these methods
7
Serial Organization Records are stored in chronological order (in order as they are input or occur) Examples Recording of telephone charges ATM transactions Telephone queues
8
Sequential Organization
Records are stored in order based on a key field Key field A field containing a value that uniquely identifies a record Examples Names Account numbers Student numbers Example Phone directories
9
Direct (Relative) Organization
Each record is stored based on a physical address or location on the device Address is calculated from the value stored in the record’s key field Randomizing routine or hashing algorithm does the conversion Disadvantages Creating a good randomizing routine is difficult Collisions Wasted space on the device can be considerable Sequential processing may not be possible
10
Indexed Organization Records can be processed both sequentially and nonsequentially using indexes
11
File Access Method by which computer programs read or write records on a file Sequential access Direct (random) access
12
Sequential Access Every record on the file is processed starting with the first record until EOF is reached
13
Sequential Access Suppose we only want to access the 4th record
The 3 records that precede it must be accessed first Inefficient when records must be processed in a sequence other than their physical order on the device
14
Sequential Access Is Efficient When…
A large number of the records on the file must be accessed at any given time
15
Direct (Random) Access
A high percentage of today’s information processing must be done nonsequentially Records are located by knowing their physical locations or addresses on the device rather than their positions relative to other records
16
Compare Looking for a Recording on a CD versus on a Cassette Tape
SEQUENTIAL DIRECT Data stored on a CD device (direct-access) can be accessed either sequentially or nonsequentially Data stored on a tape (sequential access) can be accessed only sequentially
17
Main Disadvantage of Nonsequential Access
You must know a record’s address to find it Process of calculating or looking up an address takes more time than getting the “next record” as is done with sequential access You must weigh… amount of time it takes to find individual records number of records to be accessed
18
Types of Files Used by Business Systems
Master Files Table Files Transaction Files Log Files Mirror Files Archive Files Temporary Files
19
Master Files Contain the current information for a system
customer file student file telephone directory
20
Table Files Type of master file Change infrequently
Stored in a tabular format Zipcode
21
Transaction Files Contain the day-to-day information generated from business activities Used to update or process the master file
22
Temporary Files Created and used whenever needed by a system
23
Mirror Files Exact duplicates of other files
Help minimize the risk of downtime in cases when the original becomes unusable Must be modified each time the original file is changed
24
Log Files Contain copies of master and transaction records in order to chronicle any changes that are made to the master file Facilitate auditing Provide mechanism for recovery in case of system failure
25
Archive Files Backup files that contain historical versions of other files
26
Sequential File Merging Programs
Combine two or more sequential or serial files into a single file Examples merge the phone directories of two cities combine transactions from more than one day Merging cassette tapes + Tape B Tape A Tape C
27
Merging Cassette Tapes
+ Tape B Tape A Tape C Copy all the music from tape A to tape C Without rewinding tape C, copy all the music from tape B onto tape C
28
Suppose the Cassette Tapes have Been Recorded so that Music Is in Order by Recording Date—You Want the Merged Tape to Be in the Same Order + Tape B Tape A Tape C You need to switch back and forth between Tape A and Tape B to make sure they are copied in the correct order to Tape C
29
Let’s Merge 2 Phone Directory Files
Adams Baker Desai Fisher Smith Names on File 1 Andrews Berkowitz Crown Fisher Miller Patel Tripp Wu Names on File 2
30
Let’s Merge 2 Phone Directory Files
Adams Baker Desai Fisher Smith Names on File 1 Andrews Berkowitz Crown Fisher Miller Patel Tripp Wu Names on File 2 Merge File Adams
31
Let’s Merge 2 Phone Directory Files
Adams Baker Desai Fisher Smith Names on File 1 Andrews Berkowitz Crown Fisher Miller Patel Tripp Wu Names on File 2 Merge File Adams Andrews
32
Let’s Merge 2 Phone Directory Files
Adams Baker Desai Fisher Smith Names on File 1 Andrews Berkowitz Crown Fisher Miller Patel Tripp Wu Names on File 2 Merge File Adams Andrews Baker
33
Let’s Merge 2 Phone Directory Files
Adams Baker Desai Fisher Smith Names on File 1 Andrews Berkowitz Crown Fisher Miller Patel Tripp Wu Names on File 2 Merge File Adams Andrews Baker Berkowitz
34
Let’s Merge 2 Phone Directory Files
Adams Baker Desai Fisher Smith Names on File 1 Andrews Berkowitz Crown Fisher Miller Patel Tripp Wu Names on File 2 Merge File Adams Andrews Baker Berkowitz Crown
35
Let’s Merge 2 Phone Directory Files
Adams Baker Desai Fisher Smith Names on File 1 Andrews Berkowitz Crown Fisher Miller Patel Tripp Wu Names on File 2 Merge File Adams Andrews Baker Berkowitz Crown Desai
36
Let’s Merge 2 Phone Directory Files
Adams Baker Desai Fisher Smith Names on File 1 Andrews Berkowitz Crown Fisher Miller Patel Tripp Wu Names on File 2 Merge File Adams Andrews Baker Berkowitz Crown Desai Fisher
37
Let’s Merge 2 Phone Directory Files
Adams Baker Desai Fisher Smith Names on File 1 Andrews Berkowitz Crown Fisher Miller Patel Tripp Wu Names on File 2 Merge File Adams Andrews Baker Berkowitz Crown Desai Fisher Fisher
38
Let’s Merge 2 Phone Directory Files
Adams Baker Desai Fisher Smith Names on File 1 Andrews Berkowitz Crown Fisher Miller Patel Tripp Wu Names on File 2 Merge File Adams Andrews Baker Berkowitz Crown Desai Fisher Miller
39
Let’s Merge 2 Phone Directory Files
Adams Baker Desai Fisher Smith Names on File 1 Andrews Berkowitz Crown Fisher Miller Patel Tripp Wu Names on File 2 Merge File Adams Andrews Baker Berkowitz Crown Desai Fisher Miller Patel
40
Let’s Merge 2 Phone Directory Files
Adams Baker Desai Fisher Smith Names on File 1 Andrews Berkowitz Crown Fisher Miller Patel Tripp Wu Names on File 2 Merge File Adams Andrews Baker Berkowitz Crown Desai Fisher Miller Patel Smith
41
Let’s Merge 2 Phone Directory Files
Adams Baker Desai Fisher Smith Names on File 1 Andrews Berkowitz Crown Fisher Miller Patel Tripp Wu Names on File 2 Merge File Adams Andrews Baker Berkowitz Crown Desai Fisher Miller Patel Smith There are no more records on this file We finish copying records from this file
42
Let’s Merge 2 Phone Directory Files
Adams Baker Desai Fisher Smith Names on File 1 Andrews Berkowitz Crown Fisher Miller Patel Tripp Wu Names on File 2 Merge File Adams Andrews Baker Berkowitz Crown Desai Fisher Miller Patel Smith We finish copying records from this file Tripp
43
Let’s Merge 2 Phone Directory Files
Adams Baker Desai Fisher Smith Names on File 1 Andrews Berkowitz Crown Fisher Miller Patel Tripp Wu Names on File 2 Merge File Adams Andrews Baker Berkowitz Crown Desai Fisher Miller Patel Smith Tripp Wu
44
Let’s Examine the Logic for a Merge Program (page 391)
Terminate is called when either input file reaches EOF The indicators, Done-File1 and Done-File2, are used to ensure that neither file is read past EOF Terminate finishes processing whichever file still contains records
45
Initialize Assign initial values Read a record from each input file
46
The Merge Routine Determines which Record to Write on the Merge File
47
How Does Terminate Finish Processing the Files?
48
Done-File1 and Done-File2
Makes sure that neither file is read past EOF Initialized to “NO” in Initialize routine As long as both indicators contain the value “NO”, Mainline continues to do the Merge routine As soon as one of the indicators becomes “YES”, Mainline calls Terminate When Terminate is called, either Done-File1 or Done-File2 is “NO”—the other indicator is “YES” Terminate finishes processing the file that still contains records Done-File1 and Done-File2
49
Sequential File Matching Programs
Transaction File Information from records contained on the master file are needed to process the transaction records The example in section 9.4 (page 393) generates a billing report using… Purchase amounts from transaction records Customer numbers, customer names, addresses, and discount type from master records Master File Billing Report
50
Why Use 2 Files to Produce a Billing Report?
Accuracy of data input Speed of data input Each time a billing report is generated, you must enter… amount of purchases You do not need to enter constant data… customer names customer addresses discount type
51
Data Dictionary—Input Files (page 394)
Both files are in the same order—increasing order by customer number All data have been validated prior to this program Why do both the Master-Record and Transaction-Record contain the customer number? There may be… no master record for a transaction record no transaction record for a master record a match based on the customer numbers—there may be one or more transaction records for a matching master record
52
The Report See page 393 When there is a match, line 5 is generated
When there is a transaction with no master, line 6 is generated When there is a master with no transaction, line 7 is generated
53
Let’s Consider Some “Real” Data
Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8
54
Let’s Consider Some “Real” Data
Master File Customer Numbers Match No Trans. Match No Trans. No Trans. Match No Trans. 11 No Trans. Transaction File Customer Numbers 1 Match 4 Match 5 No Master 8 Match
55
Hierarchy Chart (page 396)
56
Mainline Routine What is High-Values?
makes sure that we don’t stop processing until both files are at EOF makes sure that we don’t read “past” EOF Look at Read-Mast (page 398) and Read-Trans (page 399) when EOF is obtained, High-Values is moved to the customer number (Cust-No-M or Cust-No-T)
57
How Does Initialize Use High-Values (page 397)
ASSIGN names and initial values in work area HEADING-1 “BILLING REPORT” “PAGE” PAGE-NUMBER = 0 HEADING-2 “CUST.” “NAME” “ADDRESS” “PURCHASES” “BILLING” OTHER LINES-COUNTER = 0 MAX-LINES = 49 HIGH-VALUES PURCH-AMT-TOTAL BILL-AMT-TOTAL CURRENT-CUST-NO OPEN files DO READ-MAST routine IF CUST-NO-M = HIGH-VALUES THEN WRITE “MASTER FILE IS EMPTY” on report ENDIF DO READ-TRANS routine IF CUST-NO-T = HIGH-VALUES THEN WRITE “TRANSACTION FILE IS EMPTY” on report LINES-COUNTER = MAX-LINES ENDINITIALIZE
58
Let’s Look at the Sample Files Again and See How Process-Inputs (page 398) Works
Initialize reads a record from each input file Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8
59
Let’s Look at the Sample Files Again and See How Process-Inputs (page 398) Works
Process-Inputs calls Match (see page 400) Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8
60
What Does Match Do? Master File Customer Numbers 1 2 4 6 7 8 9 11
Transaction File Customer Numbers 1 4 5 8 Initializes Purch-Amt-Total and Bill-Amt-Total to zero Purch-Amt-Total accumulates the total amount of purchases for all transactions with the current customer number Bill-Amt-Total accumulates the total billing amount for all transactions with the current customer number The current customer number is saved in Current-Cust-No to determine when to stop executing the loop that follows The loop calls Calculations to add the appropriate amounts to the totals The next transaction record is read
61
What Does Match Do? Master File Customer Numbers 1 2 4 6 7 8 9 11
Transaction File Customer Numbers 1 4 5 8 Initializes Purch-Amt-Total and Bill-Amt-Total to zero Purch-Amt-Total accumulates the total amount of purchases for all transactions with the current customer number Bill-Amt-Total accumulates the total billing amount for all transactions with the current customer number The current customer number is saved in Current-Cust-No to determine when to stop executing the loop that follows The loop calls Calculations to add the appropriate amounts to the totals The next transaction record is read If the transaction has the same customer number as the current customer number, the loop is done again Otherwise, we write a line on the report, and exit the routine
62
We Exit Match and Return to Process-Inputs to Read the Next Master
Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8
63
The Master Is Less Than the Transaction
Process-Inputs Return = Cust-No-M: Cust-No-T Do Match > < No-Mast Read-Mast No-Trans Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8
64
What Does No-Trans (page 399) Do?
Writes a line on the report Returns to Process-Inputs Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8
65
We Return to Process-Inputs to Read the Next Master
Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8
66
We Have a Match Master File Customer Numbers 1 2 4 6 7 8 9 11
Transaction File Customer Numbers 1 4 5 8 Process-Inputs Cust-No-M: > < Cust-No-T = Do Do Do No-Trans Match No-Mast Do Do Read-Mast Read-Mast Return
67
What Does Match Do? Master File Customer Numbers 1 2 4 6 7 8 9 11
Transaction File Customer Numbers 1 4 5 8 Initializes Purch-Amt-Total and Bill-Amt-Total to zero Purch-Amt-Total accumulates the total amount of purchases for all transactions with the current customer number Bill-Amt-Total accumulates the total billing amount for all transactions with the current customer number The current customer number is saved in Current-Cust-No to determine when to stop executing the loop that follows The loop calls Calculations to add the appropriate amounts to the totals The next transaction is read
68
What Does Match Do? Master File Customer Numbers 1 2 4 6 7 8 9 11
Transaction File Customer Numbers 1 4 5 8 Initializes Purch-Amt-Total and Bill-Amt-Total to zero Purch-Amt-Total accumulates the total amount of purchases for all transactions with the current customer number Bill-Amt-Total accumulates the total billing amount for all transactions with the current customer number The current customer number is saved in Current-Cust-No to determine when to stop executing the loop that follows The loop calls Calculations to add the appropriate amounts to the totals The next transaction is read If the transaction has the same customer number as the current customer number, the loop is done again Otherwise, we write a line on the report, and exit the routine
69
What Does Match Do? Master File Customer Numbers 1 2 4 6 7 8 9 11
Transaction File Customer Numbers 1 4 5 8 Initializes Purch-Amt-Total and Bill-Amt-Total to zero Purch-Amt-Total accumulates the total amount of purchases for all transactions with the current customer number Bill-Amt-Total accumulates the total billing amount for all transactions with the current customer number The current customer number is saved in Current-Cust-No to determine when to stop executing the loop that follows The loop calls Calculations to add the appropriate amounts to the totals
70
What Does Match Do? Master File Customer Numbers 1 2 4 6 7 8 9 11
Transaction File Customer Numbers 1 4 5 8 Initializes Purch-Amt-Total and Bill-Amt-Total to zero Purch-Amt-Total accumulates the total amount of purchases for all transactions with the current customer number Bill-Amt-Total accumulates the total billing amount for all transactions with the current customer number The current customer number is saved in Current-Cust-No to determine when to stop executing the loop that follows The loop calls Calculations to add the appropriate amounts to the totals The next transaction is read If the transaction has the same customer number as the current customer number, the loop is done again Otherwise, we write a line on the report, and exit the routine
71
We Exit Match and Return to Process-Inputs to Read the Next Master
Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8
72
The Master Is Greater Than the Transaction
Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8 Process-Inputs Cust-No-M: > < Cust-No-T = Do Do Do No-Trans Match No-Mast Do Do Read-Mast Read-Mast Return
73
What Does No-Mast (page 401) Do?
Writes a line on the report Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8
74
What Does No-Mast (page 401) Do?
Writes a line on the report Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8 Reads transaction records until the customer number on the transaction record has changed
75
What Does No-Mast (page 401) Do?
Writes a line on the report Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8 Reads transaction records until the customer number on the transaction record has changed
76
We Return to Process-Inputs—Notice that a Master Record is NOT Read
Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8 Process-Inputs Cust-No-M: > < Cust-No-T = Do Do Do No-Trans Match No-Mast Do Do Read-Mast Read-Mast Return
77
We Return to Mainline, Which Sends Us Back to Process-Inputs--The Master Is Less Than the Transaction Process-Inputs Return = Cust-No-M: Cust-No-T Do Match > < No-Mast Read-Mast No-Trans Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8
78
What Does No-Trans (page 399) Do?
Writes a line on the report Returns to Process-Inputs Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8
79
We Return to Process-Inputs to Read the Next Master
Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8
80
Once Again, We Do No-Trans
Write a line on the report Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8
81
Once Again, We Do No-Trans
Read the next master Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8
82
We Have a Match Initializes Purch-Amt-Total and Bill-Amt-Total to zero
Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8 Initializes Purch-Amt-Total and Bill-Amt-Total to zero Purch-Amt-Total accumulates the total amount of purchases for all transactions with the current customer number Bill-Amt-Total accumulates the total billing amount for all transactions with the current customer number The current customer number is saved in Current-Cust-No to determine when to stop executing the loop that follows The loop calls Calculations to add the appropriate amounts to the totals The next transaction record is read
83
We Have a Match Master File Customer Numbers 1 2 4 6 7 8 9 11
Transaction File Customer Numbers 1 4 5 8 High-Values Initializes Purch-Amt-Total and Bill-Amt-Total to zero Purch-Amt-Total accumulates the total amount of purchases for all transactions with the current customer number Bill-Amt-Total accumulates the total billing amount for all transactions with the current customer number The current customer number is saved in Current-Cust-No to determine when to stop executing the loop that follows The loop calls Calculations to add the appropriate amounts to the totals The next transaction record is read We get EOF which moves High-Values to the customer number The customer number is not the same, so we write a line on the report, and exit the routine
84
We Exit Match and Return to Process-Inputs to Read the Next Master
Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8 High-Values
85
From Now Until EOF on the Master File, the Customer Number on the Master will be < the Customer Number on the Transaction Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8 High-Values
86
So, We Continue to Do No-Trans and Read-Mast Until We Reach EOF on the Master
Master File Customer Numbers 1 2 4 6 7 8 9 11 Transaction File Customer Numbers 1 4 5 8 High-Values
87
If the Master File Had Ended Before the Transaction File, Then…
We Would Have Moved High-Values to the Master’s Customer Number and Kept Doing No-Mast Until EOF Was Obtained on the Transaction File
88
Sequential File Update Programs
Old master file Transaction file Modifies a sequential master file by adding, changing, and deleting records Similar logic to matching programs matching programs -- records from the master file are used to process the transactions update programs –records from the transaction file are used to add, change, and delete records on the master file Update program New master file Update report Exception report
89
Sequential File Update Programs
Transaction file Old master file New master file Update report Exception report The old master file is saved as backup The new master file becomes the old master file the next time the update program is executed
90
Two Reports are Produced (page 408)
Update program Transaction file Old master file New master file Update report Exception report How are two reports produced simultaneously with one printer? Spooling
91
Spooling Update program
Update Report Exception Report Reports are written to a disk or tape (instead of to the printer) Reports are printed using a utility program whenever the printer is available
92
Let’s Compare the Processing with Making Changes on a Cassette Tape on which You Have Previously Recorded Songs Delete Song 4 Song 1 Song 2 Song 3 Song 4 Song 5 Song 1 Song 2 Song 3 Song 5
93
Let’s Compare the Processing with Making Changes on a Cassette Tape on which You Have Previously Recorded Songs Change Song 3 Song 3 Song 1 Song 2 Song 3 Song 4 Song 5 Song 1 Song 2 Song 4 Song 5
94
Let’s Study the Input Files (page 410)
Each transaction record contains a code indicating whether the transaction is for an add (A), change (C), or delete (D) Both files are in sorted order by customer number Transaction file has been previously validated to ensure that … the code is valid there is a maximum of 1 transaction for each customer number
95
Adds, Changes, and Deletes
Code = A new customer a new master record is created with the data from the transaction record an error will occur if the master record already exists Code = D customer is to be deleted (account closed) the transaction only contains the account number an error will occur if the master record does NOT exist Code = C change to record on master file A new master record is created with the changes from the transaction record an error will occur if the master does NOT exist
96
What Changes Can Occur? customer name customer address discount type
customer number can NOT be changed
97
Look at Mainline (page 412)
What does it mean if Cust-No-T = High-Values after returning from Initialize? there were no records on the Transaction File the program is terminated because it does not make sense to do an update program if there are NO records on the transaction file Initialize writes an error on the Exception Report Mainline does not check Cust-No-M after returning from Initialize. Why not? if there are no records on the master file, the update program can be used to create a new master file all of the transactions must be adds Mainline calls Update-File until both files reach EOF
98
Look at Initialize (page 413)
It doesn’t matter whether the Master File or Transaction File is read first Initialize writes an error if there are no records on the Transaction File No error occurs if the Master File is empty
99
Mainline Calls Update-File (page 414)
100
What Happens if Cust-No-M < Cust-No-T?
No-Trans is done (page 415) The record on the old master file is copied to the new master file The next master record is read
101
What Happens if Cust-No-M > Cust-No-T?
No-Mast is done (page 416) The only “valid” code is A (add) Do Add-Mast (page 418) Write the new master record Write a line on the update report Read the next transaction
102
What Happens if Cust-No-M = Cust-No-T?
Match is done (page 415) If the Code is “A”, an error results An error message is written on the report the next transaction is read If the Code is “D”, the master is deleted Delete-Mast (page 416) writes a message on the report the next master is read If the code is “C”, the master is changed Change-Mast (page 417) writes the changed master on the master file and a message on the report
103
What Data Should We Use to Test the Program?
Combinations for… master < transaction master = transaction master > transaction < condition followed by… another < condition > condition = condition = condition followed by… another = condition < condition > condition followed by… another > condition
104
What Data Should We Use to Test the Program?
Add with… = condition < condition > condition Change with… Delete with One data set should have the master file reach EOF before the transaction file ends Another data set should have the transaction file reach EOF before the master file ends
105
Let’s Consider Nonsequential Processing
Advantages You can find a record without accessing all preceding records Transaction records can be in any order—they don’t have to be sorted Updating does not require an entirely new master file Disadvantages Creation of a backup must be done as a separate processing step—no old master to use as backup To access a record, the program must first determine the address—this is slow compared to “getting the next record”
106
Updates – Direct Files Access records by calculating their physical addresses Adding a record calculate where it should be stored write it on the device Changing a record change the values stored in particular fields rewrite the record on the device in the same physical location it was in originally Deleting a record not physically deleted marked as a deletion—we logically delete it each time we access a record, we check to see whether it has been logically deleted
107
Updates - Indexed Files
Three areas are used on the storage device index area contains record keys and addresses stored in sequential order prime data area contains records originally on file overflow data area Contains records added to the file Need for reorganization Indexed files can be maintained by programmers even when the programming language does not provided for indexed processing maintain indexes in tables in sequential files store records in a direct file
108
Pointers, Chains, and Rings
Pointers are used in nonsequential processing to maintain a logical order even though records are located randomly Pointers create chains of records
109
Pointers, Chains, and Rings
Sometimes files contain more than one pointer This example shows forward and backward pointers
110
Pointers, Chains, and Rings
When a ring is used, there is no “end of chain”
111
Why Use Databases Instead of Traditional Files?
Data redundancy Are the same fields are used in many different files Data integrity Are the same data maintained in different files consistent? Data independence If a change is made to the file or database structure, do programs have to be changed to accommodate the new structure?
112
Database Management System (DBMS)
A set of programs that serve as the interface between application programs and the database Provides capabilities for the following… creating or modifying the file structure field names field lengths data types special attributes confidential fields can be accessed only by providing the correct password protected fields can be access but cannot be changed without providing the correct password Data entry importing data from another file downloading data from another computer or server Entering data interactively using input forms or screens Data retrieval (extracting data) programming languages allow for customization
113
Models for Database Organization
Physical view deals with the actual location and storage of data as well as the pointers—DBMS worries about this Logical view deals with the relationship between records and fields—programmer works with this There are many models used to represent logical views hierarchical model network model relational model object-oriented model
114
Hierarchical Model Developed in 1960s to be used on large mainframes
One-to-many relationships Each record is called a node Subordinate items are called children Superior items are called parents
115
Network Model Many-to-many relationships are possible
116
Relational Model Represents data in two-dimensional tables
Rows represent records Columns represent fields Name Test 1 Test 2 Test 3 Test 4 Test 5 Test 6 Test 7 Cohn 48 50 68 89 98 92 80 Kim 85 77 90 79 81 Katsumoto 91 41 76 58 87 Brown 72 Johnson 78 45 69 73 Patel 100 88 Jerwinski
117
Object-Oriented Models
Integrates object-oriented concepts (such as encapsulation and inheritance) with traditional database capabilities Can handle user-defined data types
118
How Do You Select a File or Database Organization?
Ease of implementing and maintaining a particular type of file or database organization Availability of software Cost The nature of the application volatility (frequency of changes) activity (percentage of records that are actually used each time the program is run) query (retrieval of specific information) requirements security requirements
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.