Docsity

Relational Database Manuel, Lecture notes of Relational Database Management Systems (RDBMS)

Partial preview of the text

Download Relational Database Manuel and more Lecture notes Relational Database Management Systems (RDBMS) in PDF only on Docsity!

CNG 351

Data Management

and File Structures

REFERENCE BOOKS:

  • Connolly, T. M., & Begg, C. E. (2004). Database systems: A

practical approach to design, implementation and management

(4th ed.). Uttar Pradesh, India: Pearson India Education Services.

Used in topics: 1- 8 - 9 - 10 - 13 - 14

  • Elmasri, R. A., & Navathe, S. B. (2003). Fundamentals of

database systems (4th ed.). Boston: Pearson.

Used in topics: 3- 4 - 5 - 7

  • Connolly, T. M., & Begg, C. E. (2003). Database solutions: A step-

by-step guide to building databases (2nd ed.). Harlow: Pearson.

Used in topics: 2- 6

  • Earp, R., & Bagui, S. (2002). Learning SQL: A Step-by-Step Guide

using Oracle.

Used in topics: 11- 12

Textbook Editor: Y. E.

Chapter

Introduction to Databases

Chapter Objectives

In this chapter you will learn: n Some common uses of database systems. n The characteristics of file-based systems. n The problems with the file-based approach. n The meaning of the term ‘database’. n The meaning of the term ‘database management system’ (DBMS). n The typical functions of a DBMS. n The major components of the DBMS environment. n The personnel involved in the DBMS environment. n The history of the development of DBMSs. n The advantages and disadvantages of DBMSs.

The history of database system research is one of exceptional productivity and startling economic impact. Barely 20 years old as a basic science research field, database research has fueled an information services industry estimated at $10 bil- lion per year in the U.S. alone. Achievements in database research underpin funda- mental advances in communications systems, transportation and logistics, financial management, knowledge-based systems, accessibility to scientific literature, and a host of other civilian and defense applications. They also serve as the foundation for considerable progress in the basic science fields ranging from computing to biology. (Silberschatz et al. , 1990, 1996)

This quotation is from a workshop on database systems at the beginning of the 1990s and expanded upon in a subsequent workshop in 1996, and it provides substantial motivation for the study of the subject of this book: the database system. Since these workshops, the importance of the database system has, if anything, increased with the significant devel- opments in hardware capability, hardware capacity, and communications, including the

TOPIC 1

1.1 Introduction (^) | 5

Purchases from the supermarket

When you purchase goods from your local supermarket, it is likely that a database is accessed. The checkout assistant uses a bar code reader to scan each of your purchases. This is linked to an application program that uses the bar code to find out the price of the item from a product database. The program then reduces the number of such items in stock and displays the price on the cash register. If the reorder level falls below a specified threshold, the database system may automatically place an order to obtain more stocks of that item. If a customer telephones the supermarket, an assistant can check whether an item is in stock by running an application program that determines availability from the database.

Purchases using your credit card

When you purchase goods using your credit card, the assistant normally checks that you have sufficient credit left to make the purchase. This check may be carried out by tele- phone or it may be carried out automatically by a card reader linked to a computer system. In either case, there is a database somewhere that contains information about the purchases that you have made using your credit card. To check your credit, there is a database applica- tion program that uses your credit card number to check that the price of the goods you wish to buy together with the sum of the purchases you have already made this month is within your credit limit. When the purchase is confirmed, the details of the purchase are added to this database. The application program also accesses the database to check that the credit card is not on the list of stolen or lost cards before authorizing the purchase. There are other application programs to send out monthly statements to each cardholder and to credit accounts when payment is received.

Booking a holiday at the travel agents

When you make inquiries about a holiday, the travel agent may access several databases containing holiday and flight details. When you book your holiday, the database system has to make all the necessary booking arrangements. In this case, the system has to ensure that two different agents do not book the same holiday or overbook the seats on the flight. For example, if there is only one seat left on the flight from London to New York and two agents try to reserve the last seat at the same time, the system has to recognize this situ- ation, allow one booking to proceed, and inform the other agent that there are now no seats available. The travel agent may have another, usually separate, database for invoicing.

Using the local library

Your local library probably has a database containing details of the books in the library, details of the readers, reservations, and so on. There will be a computerized index that allows readers to find a book based on its title, or its authors, or its subject area. The data- base system handles reservations to allow a reader to reserve a book and to be informed by mail when the book is available. The system also sends reminders to borrowers who have failed to return books by the due date. Typically, the system will have a bar code

TOPIC 1

(^6) | Chapter 1 z Introduction to Databases

reader, similar to that used by the supermarket described earlier, which is used to keep track of books coming in and going out of the library.

Taking out insurance

Whenever you wish to take out insurance, for example personal insurance, building, and contents insurance for your house, or car insurance, your broker may access several databases containing figures for various insurance organizations. The personal details that you supply, such as name, address, age, and whether you drink or smoke, are used by the database system to determine the cost of the insurance. The broker can search several databases to find the organization that gives you the best deal.

Renting a video

When you wish to rent a video from a video rental company, you will probably find that the company maintains a database consisting of the video titles that it stocks, details on the copies it has for each title, whether the copy is available for rent or whether it is currently on loan, details of its members (the renters), and which videos they are currently renting and date they are returned. The database may even store more detailed information on each video, such as its director and its actors. The company can use this information to mon- itor stock usage and predict future buying trends based on historic rental data.

Using the Internet

Many of the sites on the Internet are driven by database applications. For example, you may visit an online bookstore that allows you to browse and buy books, such as Amazon.com. The bookstore allows you to browse books in different categories, such as computing or management, or it may allow you to browse books by author name. In either case, there is a database on the organization’s Web server that consists of book details, availability, shipping information, stock levels, and on-order information. Book details include book titles, ISBNs, authors, prices, sales histories, publishers, reviews, and detailed descriptions. The database allows books to be cross-referenced: for example, a book may be listed under several categories, such as computing, programming languages, bestsellers, and recommended titles. The cross-referencing also allows Amazon to give you informa- tion on other books that are typically ordered along with the title you are interested in. As with an earlier example, you can provide your credit card details to purchase one or more books online. Amazon.com personalizes its service for customers who return to its site by keeping a record of all previous transactions, including items purchased, shipping, and credit card details. When you return to the site, you can now be greeted by name and you can be presented with a list of recommended titles based on previous purchases.

Studying at university

If you are at university, there will be a database system containing information about your- self, the course you are enrolled in, details about your grant, the modules you have taken in previous years or are taking this year, and details of all your examination results. There

TOPIC 1

(^8) | Chapter 1 z Introduction to Databases

n What three-bedroom properties do you have for sale with a garden and garage? n What flats do you have for rent within three miles of the city center? n What is the average rent for a two-bedroom flat? n What is the total annual salary bill for staff? n How does last month’s turnover compare with the projected figure for this month? n What is the expected monthly turnover for the next financial year?

Increasingly, nowadays, clients, senior managers, and staff want more and more informa- tion. In some areas there is a legal requirement to produce detailed monthly, quarterly, and annual reports. Clearly, the manual system is inadequate for this type of work. The file- based system was developed in response to the needs of industry for more efficient data access. However, rather than establish a centralized store for the organization’s operational data, a decentralized approach was taken, where each department, with the assistance of Data Processing (DP) staff, stored and controlled its own data. To understand what this means, consider the DreamHome example. The Sales Department is responsible for the selling and renting of properties. For example, whenever a client approaches the Sales Department with a view to marketing his or her property for rent, a form is completed, similar to that shown in Figure 1.1(a). This gives details of the property such as address and number of rooms together with the owner’s details. The Sales Department also handles inquiries from clients, and a form similar to the one shown in Figure 1.1(b) is completed for each one. With the assistance of the DP Department, the Sales Department creates an information system to handle the renting of property. The system consists of three files containing property, owner, and client details, as illustrated in Figure 1.2. For simplicity, we omit details relating to members of staff, branch offices, and business owners. The Contracts Department is responsible for handling the lease agreements associated with properties for rent. Whenever a client agrees to rent a property, a form is filled in by one of the Sales staff giving the client and property details, as shown in Figure 1.3. This form is passed to the Contracts Department which allocates a lease number and completes the payment and rental period details. Again, with the assistance of the DP Department, the Contracts Department creates an information system to handle lease agreements. The system consists of three files storing lease, property, and client details, containing similar data to that held by the Sales Department, as illustrated in Figure 1.4. The situation is illustrated in Figure 1.5. It shows each department accessing their own files through application programs written specially for them. Each set of departmental application programs handles data entry, file maintenance, and the generation of a fixed set of specific reports. What is more important, the physical structure and storage of the data files and records are defined in the application code. We can find similar examples in other departments. For example, the Payroll Depart- ment stores details relating to each member of staff’s salary, namely:

StaffSalary(staffNo, fName, lName, sex, salary, branchNo)

The Personnel Department also stores staff details, namely:

Staff(staffNo, fName, lName, position, sex, dateOfBirth, salary, branchNo)

TOPIC 1

1.2 Traditional File-Based Systems (^) | 9

Figure 1.

Sales Department forms: (a) Property for Rent Details form; (b) Client Details form.

TOPIC 1

1.2 Traditional File-Based Systems (^) | 11

Figure 1. File-based processing.

Figure 1. The Lease, PropertyForRent, and Client files used by Contracts.

It can be seen quite clearly that there is a significant amount of duplication of data in these departments, and this is generally true of file-based systems. Before we discuss the limitations of this approach, it may be useful to understand the terminology used in file- based systems. A file is simply a collection of records , which contains logically related

TOPIC 1

(^12) | Chapter 1 z Introduction to Databases

data. For example, the PropertyForRent file in Figure 1.2 contains six records, one for each property. Each record contains a logically connected set of one or more fields , where each field represents some characteristic of the real-world object that is being modeled. In Figure 1.2, the fields of the PropertyForRent file represent characteristics of properties, such as address, property type, and number of rooms.

Limitations of the File-Based Approach

This brief description of traditional file-based systems should be sufficient to discuss the limitations of this approach. We list five problems in Table 1.1.

Separation and isolation of data

When data is isolated in separate files, it is more difficult to access data that should be available. For example, if we want to produce a list of all houses that match the require- ments of clients, we first need to create a temporary file of those clients who have ‘house’ as the preferred type. We then search the PropertyForRent file for those properties where the property type is ‘house’ and the rent is less than the client’s maximum rent. With file systems, such processing is difficult. The application developer must synchronize the pro- cessing of two files to ensure the correct data is extracted. This difficulty is compounded if we require data from more than two files.

Duplication of data

Owing to the decentralized approach taken by each department, the file-based approach encouraged, if not necessitated, the uncontrolled duplication of data. For example, in Figure 1.5 we can clearly see that there is duplication of both property and client details in the Sales and Contracts Departments. Uncontrolled duplication of data is undesirable for several reasons, including: n Duplication is wasteful. It costs time and money to enter the data more than once. n It takes up additional storage space, again with associated costs. Often, the duplication of data can be avoided by sharing data files. n Perhaps more importantly, duplication can lead to loss of data integrity; in other words, the data is no longer consistent. For example, consider the duplication of data between

Table 1.1 Limitations of file-based systems.

Separation and isolation of data Duplication of data Data dependence Incompatible file formats Fixed queries/proliferation of application programs

1.2.

TOPIC 1

(^14) | Chapter 1 z Introduction to Databases

does not hold the details of property owners; only the Sales Department holds these. However, Contracts has the property number (propertyNo), which can be used to find the corresponding property number in the Sales Department’s PropertyForRent file. This file holds the owner number (ownerNo), which can be used to find the owner details in the PrivateOwner file. The Contracts Department programs in COBOL and the Sales Depart- ment programs in ‘C’. Therefore, to match propertyNo fields in the two PropertyForRent files requires an application developer to write software to convert the files to some common format to facilitate processing. Again, this can be time-consuming and expensive.

Fixed queries/proliferation of application programs

From the end-user’s point of view, file-based systems proved to be a great improvement over manual systems. Consequently, the requirement for new or modified queries grew. However, file-based systems are very dependent upon the application developer, who has to write any queries or reports that are required. As a result, two things happened. In some organizations, the type of query or report that could be produced was fixed. There was no facility for asking unplanned (that is, spur-of-the-moment or ad hoc ) queries either about the data itself or about which types of data were available. In other organizations, there was a proliferation of files and application programs. Eventually, this reached a point where the DP Department, with its current resources, could not handle all the work. This put tremendous pressure on the DP staff, resulting in programs that were inadequate or inefficient in meeting the demands of the users, documentation that was limited, and maintenance that was difficult. Often, certain types of functionality were omitted including: n there was no provision for security or integrity; n recovery, in the event of a hardware or software failure, was limited or non-existent; n access to the files was restricted to one user at a time – there was no provision for shared access by staff in the same department.

In either case, the outcome was not acceptable. Another solution was required.

Database Approach All the above limitations of the file-based approach can be attributed to two factors:

(1) the definition of the data is embedded in the application programs, rather than being stored separately and independently; (2) there is no control over the access and manipulation of data beyond that imposed by the application programs.

To become more effective, a new approach was required. What emerged were the database and the Database Management System (DBMS). In this section, we provide a more formal definition of these terms, and examine the components that we might expect in a DBMS environment.

TOPIC 1

1.3 Database Approach (^) | 15

The Database

Database A shared collection of logically related data, and a description of this data, designed to meet the information needs of an organization.

We now examine the definition of a database to understand the concept fully. The database is a single, possibly large repository of data that can be used simultaneously by many departments and users. Instead of disconnected files with redundant data, all data items are integrated with a minimum amount of duplication. The database is no longer owned by one department but is a shared corporate resource. The database holds not only the organiza- tion’s operational data but also a description of this data. For this reason, a database is also defined as a self-describing collection of integrated records. The description of the data is known as the system catalog (or data dictionary or metadata – the ‘data about data’). It is the self-describing nature of a database that provides program–data independence. The approach taken with database systems, where the definition of data is separated from the application programs, is similar to the approach taken in modern software development, where an internal definition of an object and a separate external definition are provided. The users of an object see only the external definition and are unaware of how the object is defined and how it functions. One advantage of this approach, known as data abstraction , is that we can change the internal definition of an object without affect- ing the users of the object, provided the external definition remains the same. In the same way, the database approach separates the structure of the data from the application pro- grams and stores it in the database. If new data structures are added or existing structures are modified then the application programs are unaffected, provided they do not directly depend upon what has been modified. For example, if we add a new field to a record or create a new file, existing applications are unaffected. However, if we remove a field from a file that an application program uses, then that application program is affected by this change and must be modified accordingly. The final term in the definition of a database that we should explain is ‘logically related’. When we analyze the information needs of an organization, we attempt to identify entities, attributes, and relationships. An entity is a distinct object (a person, place, thing, concept, or event) in the organization that is to be represented in the database. An attribute is a property that describes some aspect of the object that we wish to record, and a relation- ship is an association between entities. For example, Figure 1.6 shows an Entity– Relationship (ER) diagram for part of the DreamHome case study. It consists of:

n six entities (the rectangles): Branch, Staff, PropertyForRent, Client, PrivateOwner, and Lease;

n seven relationships (the names adjacent to the lines): Has , Offers , Oversees , Views , Owns , LeasedBy , and Holds ;

n six attributes, one for each entity: branchNo, staffNo, propertyNo, clientNo, ownerNo, and leaseNo.

The database represents the entities, the attributes, and the logical relationships between the entities. In other words, the database holds data that is logically related. We discuss the Entity–Relationship model in detail in Chapters 11 and 12.

1.3.

TOPIC 1

1.3 Database Approach (^) | 17

  • a recovery control system, which restores the database to a previous consistent state following a hardware or software failure;
  • a user-accessible catalog, which contains descriptions of the data in the database.

(Database) Application Programs

Application A computer program that interacts with the database by issuing an program appropriate request (typically an SQL statement) to the DBMS.

Users interact with the database through a number of application programs that are used to create and maintain the database and to generate information. These programs can be conventional batch applications or, more typically nowadays, they will be online applica- tions. The application programs may be written in some programming language or in some higher-level fourth-generation language. The database approach is illustrated in Figure 1.7, based on the file approach of Figure 1.5. It shows the Sales and Contracts Departments using their application programs to access the database through the DBMS. Each set of departmental application programs handles data entry, data maintenance, and the generation of reports. However, compared with the file-based approach, the physical structure and storage of the data are now man- aged by the DBMS.

Views

With this functionality, the DBMS is an extremely powerful and useful tool. However, as the end-users are not too interested in how complex or easy a task is for the system, it could be argued that the DBMS has made things more complex because they now see

Figure 1. Database processing.

1.3.

TOPIC 1

(^18) | Chapter 1 z Introduction to Databases

more data than they actually need or want. For example, the details that the Contracts Department wants to see for a rental property, as shown in Figure 1.5, have changed in the database approach, shown in Figure 1.7. Now the database also holds the property type, the number of rooms, and the owner details. In recognition of this problem, a DBMS pro- vides another facility known as a view mechanism , which allows each user to have his or her own view of the database (a view is in essence some subset of the database). For ex- ample, we could set up a view that allows the Contracts Department to see only the data that they want to see for rental properties. As well as reducing complexity by letting users see the data in the way they want to see it, views have several other benefits:

n Views provide a level of security. Views can be set up to exclude data that some users should not see. For example, we could create a view that allows a branch manager and the Payroll Department to see all staff data, including salary details, and we could create a second view that other staff would use that excludes salary details. n Views provide a mechanism to customize the appearance of the database. For example, the Contracts Department may wish to call the monthly rent field (rent) by the more obvious name, Monthly Rent. n A view can present a consistent, unchanging picture of the structure of the database , even if the underlying database is changed (for example, fields added or removed, rela- tionships changed, files split, restructured, or renamed). If fields are added or removed from a file, and these fields are not required by the view, the view is not affected by this change. Thus, a view helps provide the program–data independence we mentioned in the previous section.

The above discussion is general and the actual level of functionality offered by a DBMS differs from product to product. For example, a DBMS for a personal computer may not support concurrent shared access, and it may provide only limited security, integrity, and recovery control. However, modern, large multi-user DBMS products offer all the above functions and much more. Modern systems are extremely complex pieces of software consisting of millions of lines of code, with documentation comprising many volumes. This is a result of having to provide software that handles requirements of a more general nature. Furthermore, the use of DBMSs nowadays requires a system that provides almost total reliability and 24/7 availability (24 hours a day, 7 days a week), even in the presence of hardware or software failure. The DBMS is continually evolving and expanding to cope with new user requirements. For example, some applications now require the storage of graphic images, video, sound, and so on. To reach this market, the DBMS must change. It is likely that new functionality will always be required, so that the functionality of the DBMS will never become static. We discuss the basic functions pro- vided by a DBMS in later chapters.

Components of the DBMS Environment

We can identify five major components in the DBMS environment: hardware, software, data, procedures, and people, as illustrated in Figure 1.8.

1.3.

TOPIC 1