Progress Database Design Guide
Progress Database Design Guide
Database Design
Guide
©
2001 Progress Software Corporation. All rights reserved.
Progress® software products are copyrighted and all rights are reserved by Progress Software Corporation.
This manual is also copyrighted and all rights are reserved. This manual may not, in whole or in part, be
copied, photocopied, translated, or reduced to any electronic medium or machine-readable form without
prior consent, in writing, from Progress Software Corporation.
The information in this manual is subject to change without notice, and Progress Software Corporation
assumes no responsibility for any errors that may appear in this document.
The references in this manual to specific platforms supported are subject to change.
Progress, Progress Results, Provision and WebSpeed are registered trademarks of Progress Software
Corporation in the United States and other countries. Apptivity, AppServer, ProVision Plus, SmartObjects,
IntelliStream, and other Progress product names are trademarks of Progress Software Corporation.
SonicMQ is a trademark of Sonic Software Corporation in the United States and other countries.
Progress Software Corporation acknowledges the use of Raster Imaging Technology copyrighted by
Snowbound Software 1993-1997 and the IBM XML Parser for Java Edition.
©
IBM Corporation 1998-1999. All rights reserved. U.S. Government Users Restricted Rights — Use,
duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
Progress is a registered trademark of Progress Software Corporation and is used by IBM Corporation in the
mark Progress/400 under license. Progress/400 AND 400® are trademarks of IBM Corporation and are used
by Progress Software Corporation under license.
Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the
United States and other countries.
Any other trademarks and/or service marks contained herein are the property of their respective owners.
.
May 2001
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Organization of This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Typographical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xii
Syntax Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Progress Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Other Useful Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Development Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
Reporting Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
4GL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
DataServers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
SQL-89/Open Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
SQL-92 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv
Deployment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv
WebSpeed. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
SQL-92 Reference. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvi
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1–1
1.1 What Is a Database? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1–2
1.2 Computerized Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1–3
Contents
iv
Contents
v
Contents
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Index–1
vi
Contents
Figures
Figure 1–1: Columns and Rows in the Customer Table . . . . . . . . . . . . . . . . . . . . . 1–5
Figure 1–2: Example of a Relational Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1–8
Figure 1–3: Selecting Records from Related Tables . . . . . . . . . . . . . . . . . . . . . . . 1–9
Figure 2–1: Relating the Customer and Order Tables . . . . . . . . . . . . . . . . . . . . . . 2–2
Figure 2–2: Relationship Between the Customer and Order Tables . . . . . . . . . . . . 2–3
Figure 2–3: Examples of a One-to-one Relationship . . . . . . . . . . . . . . . . . . . . . . . 2–3
Figure 2–4: Examples of a One-to-many Relationship . . . . . . . . . . . . . . . . . . . . . . 2–4
Figure 2–5: Examples of the Many-to-many Relationship . . . . . . . . . . . . . . . . . . . 2–4
Figure 2–6: Using a Cross-reference Table to Relate Order and Item Tables . . . . 2–5
Figure 3–1: Database Design Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3–2
Figure 4–1: Indexing the Order Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4–3
Figure 4–2: Data Compression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4–11
vii
Contents
Tables
Table 1–1: The Sports Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1–11
Table 2–1: Unnormalized Customer Table with Several Values in a
Column . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2–7
Table 2–2: Unnormalized Table with Multiple Duplicate Columns . . . . . . . . . . . . . 2–7
Table 2–3: Customer Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2–8
Table 2–4: Order Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2–8
Table 2–5: Customer Table with Repeated Data . . . . . . . . . . . . . . . . . . . . . . . . . . 2–9
Table 2–6: Customer Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2–10
Table 2–7: Order Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2–10
Table 2–8: Order Table with Derived Column . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2–12
Table 3–1: Order Table with Derived Column . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3–5
Table 4–1: Reasons for Defining Some Sports Database Indexes . . . . . . . . . . . . . 4–5
Table 4–2: Column Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4–9
Table 5–1: XREF tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–2
viii
Contents
Procedures
r-sgn2.p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–4
ix
Contents
x
Preface
Purpose
The Progress Database Design Guide introduces the fundamental principles of relational
database design. Use this book if you are unfamiliar with relational database concepts, or if you
need an advanced discussion of Progress 4GL index usage. Topics include table relationships,
normalization principles, database design basics, and indexing.
Audience
This guide is for new-users of relational database management systems and application
developers who are unfamiliar with relational database concepts.
This chapter introduces computerized databases and the relational model. It describes the
basic components of a relational database including: tables, columns (or fields), and rows
(or records). It also includes a definition of the Progress sports database.
This chapter describes the various relationships found in a relational database. It also
introduces the concept of normalization and describes the first three normal forms.
This chapter overviews the steps for analyzing and implementing a database design.
Progress Database Design Guide
This chapter explains in detail the Progress 4GL algorithms for choosing indexes.
This chapter introduces word indexes and how to use them in a Progress 4GL application.
This chapter explains what constraints and indexes are and why to define them.
This chapter introduces Java stored procedures and triggers and how to use them.
Typographical Conventions
This manual uses the following typographical conventions:
– New terms
– Code examples
xii
Preface
– System output
• Small capitals are used for Progress key functions and generic keyboard keys.
END-ERROR, GET, GO
ALT, CTRL, SPACEBAR, TAB
• When you have to press a combination of keys, they are joined by a dash. You press and
hold down the first key, then press the second key.
CTRL-X
• When you have to press and release one key, then press another key, the key names are
separated with a space.
ESCAPE H
ESCAPE CURSOR-LEFT
Syntax Notation
The syntax for each component follows a set of conventions:
• Uppercase words are keywords. Although they are always shown in uppercase, you can
use either uppercase or lowercase when using them in a procedure.
SYNTAX
• Italics identify options or arguments that you must supply. These options can be defined
as part of the syntax or in a separate syntax identified by the name in italics. In the
ACCUM function above, the aggregate and expression options are defined with the
syntax for the ACCUM function in the Progress Language Reference.
xiii
Progress Database Design Guide
• You must end all statements (except for DO, FOR, FUNCTION, PROCEDURE, and
REPEAT) with a period. DO, FOR, FUNCTION, PROCEDURE, and REPEAT
statements can end with either a period or a colon, as in this example:
• Square brackets ([ ] ) around an item indicate that the item, or a choice of one of the
enclosed items, is optional.
SYNTAX
In some instances, square brackets are not a syntax notation, but part of the language.
For example, this syntax for the INITIAL option uses brackets to bound an initial value
list for an array variable definition. In these cases, normal text brackets ( [ ] ) are used:
SYNTAX
• Braces ({ }) around an item indicate that the item, or a choice of one of the enclosed
items, is required.
In this example, you must specify the items BY and expression and can optionally specify
the item DESCENDING, in that order:
SYNTAX
{ BY expression [ DESCENDING ]}
In some cases, braces are not a syntax notation, but part of the language.
xiv
Preface
For example, a called external procedure must use braces when referencing arguments
passed by a calling procedure. In these cases, normal text braces ( { } ) are used:
SYNTAX
{ &argument-name }
In this example, EACH, FIRST, and LAST are optional, but you can only choose one:
SYNTAX
SYNTAX
• Ellipses (...) indicate that you can choose one or more of the preceding items. If a group
of items is enclosed in braces and followed by ellipses, you must choose one or more of
those items. If a group of items is enclosed in brackets and followed by ellipses, you can
optionally choose one or more of those items.
In this example, you must include two expressions, but you can optionally include more.
Note that each subsequent expression must be preceded by a comma:
SYNTAX
In this example, you must specify MESSAGE, then at least one of expression or SKIP, but
any additional number of expression or SKIP is allowed:
SYNTAX
xv
Progress Database Design Guide
In this example, you must specify {include-file, then optionally any number of argument
or &argument-name = "argument-value", and then terminate with }:
SYNTAX
{ include-file
[ argument | &argument-name = "argument-value" ] ... }
• In some examples, the syntax is too long to place in one horizontal row. In such cases,
optional items appear individually bracketed in multiple rows in order, left-to-right and
top-to-bottom. This order generally applies, unless otherwise specified. Required items
also appear on multiple rows in the required order, left-to-right and top-to-bottom. In cases
where grouping and order might otherwise be ambiguous, braced (required) or bracketed
(optional) groups clarify the groupings.
SYNTAX
In this example, ASSIGN requires one of two choices: either one or more of field, or one
of record. Other options available with either field or record are grouped with braces and
brackets. The open and close braces indicate the required order of options:
SYNTAX
xvi
Preface
Progress Messages
Progress displays several types of messages to inform you of routine and unusual occurrences:
• Compile messages inform you of errors found while Progress is reading and analyzing a
procedure prior to running it (for example, if a procedure references a table name that is
not defined in the database).
• Startup messages inform you of unusual conditions detected while Progress is getting
ready to execute (for example, if you entered an invalid startup parameter).
• Continues execution, subject to the error-processing actions that you specify, or that are
assumed, as part of the procedure. This is the most common action taken following
execution messages.
• Returns to the Progress Procedure Editor so that you can correct an error in a procedure.
This is the usual action taken following compiler messages.
• Halts processing of a procedure and returns immediately to the Procedure Editor. This
does not happen often.
Progress messages end with a message number in parentheses. In this example, the message
number is 200:
xvii
Progress Database Design Guide
Use Progress online help to get more information about Progress messages. On the Windows
platform, many Progress tools include the following Help menu options to provide information
about messages:
• Choose Help→ Recent Messages to display detailed descriptions of the most recent
Progress message and all other messages returned in the current session.
• Choose Help→ Messages, then enter the message number to display a description of any
Progress message. (If you encounter an error that terminates Progress, make a note of the
message number before restarting.)
On the UNIX platform, you can use the Progress PRO command to start a single-user mode
character Progress client session and view a brief description of a message by providing its
number. Follow these steps:
install-dir/dlc/bin/pro
3 ♦ Type the message number, and press ENTER. Details about that message number appear.
4 ♦ Press F4 to close the message, press F3 to access the Procedure Editor menu, and choose
File→ Exit.
xviii
Preface
Getting Started
Progress Electronic Documentation Installation and Configuration Guide (Hard copy only)
A booklet that describes how to install the Progress EDOC viewer and collection on UNIX
and Windows.
A manual that describes how to install and set up Progress Version 9.1 for the UNIX
operating system.
A manual that describes how to install and set up Progress Version 9.1 for all supported
Windows and Citrix MetaFrame operating systems.
A guide that provides a brief description of each new feature of the release. The booklet
also explains where to find more detailed information in the documentation set about each
new feature.
Progress Language Tutorial for Windows and Progress Language Tutorial for Character
Platform-specific tutorials designed for new Progress users. The tutorials use a
step-by-step approach to explore the Progress application development environment using
the 4GL.
xix
Progress Database Design Guide
Progress Master Glossary for Windows and Progress Master Glossary for Character (EDOC
only)
Platform-specific master glossaries for the Progress documentation set. These books are
in electronic format only.
Progress Master Index and Glossary for Windows and Progress Master Index and Glossary for
Character (Hard copy only)
Platform-specific master indexes and glossaries for the Progress hard-copy documentation
set.
A reference manual that describes the Progress startup commands and parameters in
alphabetical order.
A booklet that explains how Progress software and media are packaged. An icon-based
map groups the documentation by functionality, providing an overall view of the
documentation set. Welcome to Progress also provides descriptions of the various services
Progress Software Corporation offers.
Development Tools
Progress ADM 2 Guide
A programmer’s guide to using the Progress AppBuilder visual layout editor. AppBuilder
is a Rapid Application Development (RAD) tool that can significantly reduce the time and
effort required to create Progress applications.
Progress Basic Database Tools (Character only; information for Windows is in online help)
A guide for the Progress Database Administration tools, such as the Data Dictionary.
xx
Preface
Progress Basic Development Tools (Character only; information for Windows is in online help)
A guide for the Progress development toolset, including the Progress Procedure Editor and
the Application Compiler.
A guide for the Progress Application Debugger. The Debugger helps you trace and correct
programming errors by allowing you to monitor and modify procedure execution as it
happens.
A guide that describes how to develop and integrate an online help system for a Progress
application.
A guide that describes how to use the Progress Translation Manager tool to manage the
entire process of translating the text phrases in Progress applications.
A guide that describes how to use the Progress Visual Translator tool to translate text
phrases from procedures into one or more spoken languages.
Reporting Tools
Progress Report Builder Deployment Guide (Windows only)
An administration and development guide for generating Report Builder reports using the
Progress Report Engine.
A tutorial that provides step-by-step instructions for creating eight sample Report Builder
reports.
A guide for system administrators that describes how to set up and maintain the Results
product in a graphical environment. This guide also describes how to program, customize,
and package Results with your own products. In addition, it describes how to convert
character-based Results applications to graphical Results applications.
xxi
Progress Database Design Guide
Progress Results User’s Guide for Windows and Progress Results User’s Guide for UNIX
Platform-specific guides for users with little or no programming experience that explain
how to query, report, and update information with Results. Each guide also helps advanced
users and application developers customize and integrate Results into their own
applications.
4GL
Building Distributed Applications Using the Progress AppServer
A guide to accessing non-Progress applications from Progress. This guide describes how
to use system clipboards, UNIX named pipes, Windows dynamic link libraries, Windows
dynamic data exchange, Windows ActiveX controls, and the Progress Host Language Call
Interface to communicate with non-Progress applications and extend Progress
functionality.
A guide to developing Progress applications for markets worldwide. The guide covers
both internationalization—writing an application so that it adapts readily to different
locales (languages, cultures, or regions)—and localization—adapting an application to
different locales.
A three-volume reference set that contains extensive descriptions and examples for each
statement, phrase, function, operator, widget, attribute, method, and event in the Progress
language.
xxii
Preface
Database
Progress Database Administration Guide and Reference
This guide describes Progress database administration concepts and procedures. The
procedures allow you to create and maintain your Progress databases and manage their
performance.
DataServers
Progress DataServer Guides
These guides describe how to use the DataServers to access non-Progress databases. They
provide instructions for building the DataServer modules, a discussion of programming
considerations, and a tutorial. Each DataServer has its own guide, for example, the
Progress DataServer for ODBC Guide, the Progress DataServer for ORACLE Guide, or
the Progress/400 Product Guide.
The Enterprise DataServer for ODBC includes MERANT ODBC drivers for all the
supported data sources. For configuration information, see the MERANT documentation,
which is available as a PDF file in installation-path\odbc. To read this file you must
have the Adobe Acrobat Reader Version 3.1 or higher installed on your system. If you do
not have the Adobe Acrobat Reader, you can download it from the Adobe Web site at:
http://www.adobe.com/prodindex/acrobat/readstep.html.
SQL-89/Open Access
Progress Embedded SQL-89 Guide and Reference
A guide that describes how to write and deploy Java and ActiveX applications that run as
clients of the Progress AppServer. The guide includes information about how to expose
the AppServer as a set of Java classes or as an ActiveX server.
xxiii
Progress Database Design Guide
A user guide and reference for programmers who use interactive Progress/SQL-89. It
includes information on all supported SQL-89 statements, SQL-89 Data Manipulation
Language components, SQL-89 Data Definition Language components, and supported
Progress functions.
SQL-92
Progress Embedded SQL-92 Guide and Reference
A guide to the Java Database Connectivity (JDBC) interface and the Progress SQL-92
JDBC driver. It describes how to set up and use the driver and details the driver’s support
for the JDBC interface.
A guide to the ODBC interface and the Progress SQL-92 ODBC driver. It describes how
to set up and use the driver and details the driver’s support for the ODBC interface.
A user guide and reference for programmers who use Progress SQL-92. It includes
information on all supported SQL-92 statements, SQL-92 Data Manipulation Language
components, SQL-92 Data Definition Language components, and Progress functions. The
guide describes how to use the Progress SQL-92 Java classes and how to create and use
Java stored procedures and triggers.
Deployment
Progress Client Deployment Guide
A guide that describes the client deployment process and application administration
concepts and procedures.
A guide to using the Developer’s Toolkit. This guide describes the advantages and
disadvantages of different strategies for deploying Progress applications and explains how
you can use the Toolkit to deploy applications with your selected strategy.
xxiv
Preface
A guide that explains how to use the Progress toolset to build applications that are portable
across all supported operating systems, user interfaces, and databases, following the
Progress programming model.
WebSpeed
Getting Started with WebSpeed
Provides an introduction to the WebSpeed Workshop tools for creating Web applications.
It introduces you to all the components of the WebSpeed Workshop and takes you through
the process of creating your own Intranet application.
Provides instructions for installing WebSpeed on Windows and UNIX systems. It also
discusses designing WebSpeed environments, configuring WebSpeed Brokers,
WebSpeed Agents, and the NameServer, and connecting to a variety of data sources.
Provides a complete overview of WebSpeed and the guidance necessary to develop and
deploy WebSpeed applications on the Web.
A booklet that provides a brief description of each new feature of the release. The booklet
also explains where to find more detailed information in the documentation set about each
new feature.
A booklet that explains how WebSpeed software and media are packaged. Welcome to
WebSpeed! also provides descriptions of the various services Progress Software
Corporation offers.
Reference
Pocket Progress (Hard copy only)
A reference that lets you quickly look up information about the Progress language or
programming environment.
A reference that lets you quickly look up information about the SpeedScript language or
the WebSpeed programming environment.
xxv
Progress Database Design Guide
SQL-92 Reference
(These are non-Progress resources available from your technical bookseller.)
A Guide to the SQL Standard
Date, C.J., with Hugh Darwen. 1997. Reading, MA: Addison Wesley.
Melton, Jim (Digital Equipment Corporation) and Alan R. Simon. 1993. San Francisco:
Morgan Kaufmann Publishers.
xxvi
1
Introduction
• What a database is
The purpose of this chapter is to provide an introduction to the relational database. It is not
meant to provide an exhaustive resource on this topic; it is merely intended to help you get
started.
Progress Database Design Guide
• To look up a friend’s phone number, you thumb through the telephone book of the town
they live in, and search for their last name, followed by their first name. If there is more
than one occurrence of the name, you check the addresses, and by process of elimination,
you determine your friend’s phone number. The telephone book has a very simple and
restricted structure. You cannot, for instance, look up a phone number by the person’s first
name or by their address.
• To check the balance on a customer’s account, you rifle through a filing cabinet to locate
the customer’s folder and pull out the piece of paper with the current balance on it. This
database, too, has a restricted structure. You cannot, for instance, look up a customer’s
record by their address or the name of their sales representative. Furthermore, to look up
all customers with an outstanding balance of more than $1,000, you must go through all
the folders individually to find the customers that meet this criteria.
• To find a book in the library, you must first determine whether the library has the book by
looking it up in the card catalogs, either by title, author’s name, or subject matter. You note
its decimal ID number, then go to the appropriate shelf and locate the book. Of the three
databases, the card catalog is the most sophisticated because it allows you to look up a
book in at least three different ways.
To summarize, if you want to locate information quickly and effortlessly in each of these
noncomputerized databases, you must store every piece of data—name, customer folder, or
catalog card—in some sort of order. Even then, it can take anywhere from a few minutes to
several hours to locate the data, depending on the size of your database and the complexity of
the query.
1–2
Introduction
• Centralized and shared data — You enter and store all your data in the computer. This
minimizes the use of paper, files, folders, as well as the likelihood of losing or misplacing
them. Once the data is in the computer, many users can access it via a computer network.
The users’ physical or geographical locations are no longer a constraint.
• Current data — Since users can quickly update data, the data available is current and
ready to use.
• Speed and productivity — You can search, sort, retrieve, make changes, and print your
data, as well as tally up the totals more quickly than performing these tasks by hand.
• Accuracy and consistency — You can design your database to validate data entry, thus
ensuring that it is consistent and valid. For example, if a user enters OD instead of OH for
Ohio, your database can display an error message. It can also ensure that the user is unable
to delete a customer record that has an outstanding order.
• Analysis — Databases can store, track, and process large volumes of data from diverse
sources. You can use the data collected from varied sources to track the performance of an
area of business for analysis or to reveal business trends. For example, a clothes retailer
can track faulty suppliers, customers’ credit ratings, and returns of defective clothing. An
auto manufacturer can track assembly-line operation costs, product reliability, and worker
productivity.
• Security — You can protect your database by establishing a list of authorized user
identifications and passwords. The security ensures that the user can perform only the
operations that you permit. For example, you may allow the user to read data in your
database but not allow them to update or delete it.
1–3
Progress Database Design Guide
• Crash recovery — System failures are inevitable. With a database, data integrity is
assured in the event of a failure. The database management system uses a transaction log
to ensure that your data will be properly recovered when you restart after a crash.
Now that you understand the benefits of a computerized database system, let’s take a look at the
elements of relational databases.
1–4
Introduction
1.3.1 Tables
A table is a collection of logically related information treated as a unit. Figure 1–1 shows an
example of the contents of a Customer table.
Column (Fields)
1.3.2 Rows
A table is made up of rows (or records). A row is a single occurrence of the data contained in a
table. Each row is treated as a single unit. In the Customer table shown in Figure 1–1, there are
four rows, and each row contains information about an individual customer.
Similarly, each row in the Order table represents an order that a customer places, a row in the
Assignment table represents a project an employee works on, and a row in the Student Schedule
table represents a course a student takes.
1.3.3 Columns
Rows are organized as a set of columns (or fields). All rows in a table comprise the same set of
columns. In the Customer table, the columns are Cust Number, Name, and Street.
1–5
Progress Database Design Guide
1.3.4 Keys
There are two types of keys: primary and foreign. A primary key is a column (or group of
columns) whose value uniquely identifies each row in a table. Because the key value is always
unique, you can use it to detect and prevent duplicate rows. A good primary key has these
characteristics:
• It is mandatory; that is, it must store non-null values. If the column is left blank, duplicate
rows can occur.
• It is unique. For example, the social security column in an Employee or Student table is a
good key because it uniquely identifies each individual. The Cust Number column in the
Customer table uniquely identifies each customer. It is less practical to use a person’s
name because more than one customer might have the same name. Also, databases do not
detect variations in names as duplicates (for example, Cathy for Catherine, Joe for Joseph).
Furthermore, people do sometimes change their names (for example, through a marriage
or divorce).
• It is stable; that is, it is unlikely to change. As in the previous example, the social security
number is a good key not only because it uniquely identifies each individual, but it is also
unlikely to change, while a person’s or customer’s name might change.
• It is short; that is, it has few characters. Smaller columns occupy less storage space,
database searches are faster, and entries are less prone to mistakes. For example, a social
security column of 9 digits is easier to access than a name column of 30 characters.
NOTE: You can also have non-unique keys and word indexes.
A foreign key is a column value in one table that is required to match the column value of the
primary key in another table. In other words, it is the reference by one table to another. If the
foreign key value is not null, then the primary key value in the referenced table must exist. It is
this relationship of a column in one table to a column in another table that provides the relational
database with its ability to join tables. Chapter 2, “Table Relationships and Normalization”
describes this concept in more detail.
A composite key is a key composed of multiple columns.
Indexes
An index in a database operates like the index tab on a file folder. It points out one identifying
column, such as a customer’s name, that makes it easier and faster to find the information you
want.
When you use index tabs in a file folder, you use those pieces of information to organize your
files. If you index by customer name, you organize your files alphabetically. If you index by
1–6
Introduction
customer number, you organize them numerically. Indexes in the database serve the same
purpose.
You may use a single column to define a simple index, or a combination of columns to define
a compound index. To decide which columns to use, you determine how the data in the table
will be accessed. If users frequently look up customers by last name, then the last name is a
candidate for an index. It is typical to base indexes on primary keys (columns that contain
unique information).
An index has these advantages:
• Faster row search and retrieval. It is more efficient to locate a row by searching a sorted
index table than by searching an unsorted table.
• In a 4GL implementation, records are ordered automatically to support your particular data
access patterns. No matter how you change the table, when you browse or print it, the rows
appear in indexed order instead of their stored physical order on disk.
• When you define an index as unique, each row is unique. This ensures that duplicate rows
do not occur. A unique index may contain nulls. However, a primary key, although unique,
may not contain nulls.
• A combination of columns can be indexed together to allow you to sort a table in several
different ways at once (for example, sort the Projects table by a combined employee and
date column).
• When you design an index as unique, each key value must be unique.
1–7
Progress Database Design Guide
• The Customer table shows four rows, one for each individual customer. Each row has two
columns: Cust Num and Name. Each column contains exactly one data value, such as C3
and Jim Cain. The primary key is Cust Num.
• The Order table shows five rows for the orders placed by the customers in the Customer
table. Each Order row contains two columns: Cust Num (from the Customer table) and
Order Num. The primary key is Order Num. The Cust Num column is the foreign key that
relates the two tables. This relationship lets you find all the orders placed by a particular
customer, as well as information about a customer for a particular order.
• The Order-Line table shows seven rows for the order-lines of each order. Each order-line
row contains three columns: Order Num (from the Order table), Order-Line Num, and
Item Num (from the Item table). The primary key is the combination of Order Num, Order
Line. The two foreign keys (Order Num and Item Num) relate the Customer, Order, and
Item tables so that you can find the following information:
• The Item table shows four rows for each separate item. Each Item row contains two
columns: Item Num and Description. Item Num is the primary key.
1–8
Introduction
You want to find out which customers ordered ski boots. To gather this data from your database,
you must know what item number identifies ski boots and who ordered them. There is no direct
relationship between the Item table and the Customer table, so to gather the data you need, you
join four tables (using their primary/foreign key relationships). First you relate the Items to
Orders (through Order-Lines) and then the Orders to Customers. Figure 1–3 shows how this
works.
NOTE: The figures show the primary key values character data for clarity. A numeric key is
better and more efficient.
I1
I1 Ski Boots
Ski Boots OL1
OL1 I1
I1 01
01 01 C1 C1
C1 Don Smith
Don Smith
01 C1
I2 Skis OL1 I2 02 02 C1 C2 Kim Jones
I3 Ski Poles OL2 I3 02 03 C2 C3 Jim Cain
I4 Gloves OL1 I4 03 04
04 C3
C3 C4 Jane Pratt
OL1 I2 04 05 C3
OL2
OL2 I1
I1 04
04
OL1 I4 05
1 ♦ First, select the Item table row whose Description value equals ski boots. The Item
Number value is I1.
2 ♦ Next, you want to know the Orders that contain Item I1. But the Order table doesn’t
contain Items. It contains Order-Lines. So you first select the Order-Lines that contain I1,
and determine the Orders related to these Order-Lines. Orders 01 and 04 contain Item
Number I1.
1–9
Progress Database Design Guide
3 ♦ Now that you know the Order Numbers, you can find out the customers who placed the
orders. Select the 01 and 04 orders—determine the associated customer numbers. They are
C1 and C3.
4 ♦ Finally, to find out the names of Customers C1 and C3, you select the Customer table rows
that contain customer numbers C1 and C3. Don Smith and Jim Cain—ordered ski boots.
By organizing your data into tables and relating the tables with common columns, you can
perform powerful queries. The structures of tables and columns are relatively simple to
implement and modify, and the data is consistent regardless of the queries or applications used
to access the data.
1–10
Introduction
Table Description
This database holds the information necessary to track customers, take and process orders, bill
customers, and track inventory.
• A row is a collection of pieces of information about one thing, such as a specific customer.
1–11
Progress Database Design Guide
• An index is a set of pointers to rows that you use as the basis for searching, sorting, or
otherwise processing rows like customer number.
• A primary key is a column (or group of columns) whose value uniquely identifies each row
in a table. Because the key value is always unique, you can use it to detect and prevent
duplicate rows. It may not contain null data.
• An index in a database operates like the index tab on a file folder. It makes it easier to find
information.
• A foreign key is a column (or group of columns) in one table whose values are required to
match the value of a primary key in another table.
1–12
2
Table Relationships and Normalization
• Table relationships
• Normalization theory
Customer Table
Customer Number
Name Address
(Primary Key)
Common Column
Order Table
• Find all the orders for a given customer, and query information (such as order date,
promised delivery date, the actual shipping date) for each order.
• Find customer information (such as name and address) for each order using an order’s
customer number.
NOTES
• In an SQL implementation, for the larger non-numeric keys, including BINARY and
VARBINARY, use the data types NUMERIC, CHAR and VARCHAR. However, it may
be advantageous to map these to a small exact numeric data type. Do not use inexact
numeric data types such as REAL and FLOAT since the results will be non-deterministic.
2–2
Table Relationships and Normalization
Figure 2–2 shows the relationship between the Customer and the Order tables.
A Customer Order
+
B Customer Order
C Customer Order
Office Employee
Department Manager
2–3
Progress Database Design Guide
However, the business may also decide that for one office there is zero or one employee; for one
department there is no manager or there is one manager then the relationship is described as a
zero-or-one relationship.
Customer Order
Order Item
Employee Project
2–4
Table Relationships and Normalization
Order Item
Order Item
Order-Line
Order Number:
Order-Line Number:
Item Number:
Order-LineTable
Figure 2–6: Using a Cross-reference Table to Relate Order and Item Tables
2–5
Progress Database Design Guide
2.2 Normalization
This section provides an overview of normalization and the first three normal forms.
Normalization is an iterative process during which you streamline your database to reduce
redundancy and increase stability. During the normalization process you determine in which
table a particular piece of data belongs based on the data itself—its meaning to your business
and its relationship to other data. Your database design results in a data-driven, not processor
application-driven design. This results in a database implementation that is more stable over
time.
Normalization does not require you to have advanced database skills. It does require that you
know your business and know the different ways you want to relate the data in your business.
When you normalize your database, you eliminate columns that:
• Duplicate or repeat
The following sections describe the rules for the first, second and third normal form
The first rule of normalization is that you must remove duplicate columns or columns that
contain more than one value to a new table.
2–6
Table Relationships and Normalization
Here, the Order Number column has more than one entry. This makes it very difficult to perform
even the simplest tasks—for example, delete all order numbers M56 and above, find the total
number of orders for a customer, or print orders in sorted order. To perform any of those tasks
you need a complex algorithm to examine each value in the Order Number column for each row.
It is, therefore, crucial that each column in a table consists of exactly one value.
Table 2–2 shows the same Customer table in a different unnormalized format.
Here, instead of a single Order Number column, there are three separate but duplicate columns
for Order Number (Order Number1, Order Number2, and Order Number3). This format is also
not efficient. What happens if a customer has more than three orders? You must either add a
new column or clear an existing column value to make a new entry. It is difficult to estimate a
reasonable maximum number of orders for a customer. If your business is brisk, you might have
to create 200 Order Number columns for a row. Also if a customer has only 10 orders, the
database will contain 190 null values for this customer.
2–7
Progress Database Design Guide
Furthermore, it is difficult and time consuming to retrieve data with repeating columns. For
example, to determine which customer has Order Number M98, you must look at each Order
Number column individually (all 200 or more of them) in every row to find a match.
To reduce the Customer table to the first normal form, split it into two smaller tables, one table
to store only Customer information (see Table 2–3) and another to store only Order information
(see Table 2–4).
Cust Num
Name Street
(Primary Key)
M31 101
M98 101
M129 101
M56 102
M37 103
M140 103
M41 104
Note that there is only one instance of a column in the Customer and Order tables and each
column contains exactly one value. The Cust Num column in the Order table relates to the Cust
Num column in the Customer table.
2–8
Table Relationships and Normalization
A table that is normalized to the first normal form has these advantages:
• It allows you to create any number of orders for each customer without having to add new
columns
• It allows you to query and sort data for orders very quickly because you search only one
column—Order Number
2–9
Progress Database Design Guide
However, the table is not normalized to the second rule. It has these problems:
• First, note that the first three rows in this table repeat the same data for the columns: Cust
Num, Name, and Street. This is redundant data.
• Second, if the customer, Sue Jones, changes her address, you must then update all existing
rows to reflect the new address. In this case, three rows. Any rows with the old address left
unchanged leads to inconsistent data. Thus, your database lacks integrity .
• Third, you might want to trim your database by eliminating all orders before November 1,
1990, but in the process, you also lose all the customer information for Jim Hand and Steve
Tan. The unintentional loss of rows during an update operation is called an anomaly.
So, how do you resolve the problems? Note that this table contains information about an
individual customer, such as Cust Num, Name, and Street, that remain the same when you add
an order. In other words, columns like Order Num, Order Date, and Order Amount do not
pertain to the customer and do not depend on the primary key Cust Num. They should be in a
different table.
To reduce the Customer table to the second normal form, divide it into two tables, as shown in
Table 2–6 and Table 2–7.
Cust Num
Name Street
(Primary Key)
2–10
Table Relationships and Normalization
Note that the Customer table now contains only one row for each individual customer, while the
Order table contains one row for every order, and Order Number is its primary key. The Order
table contains a common column, Cust Num, that relates the Order rows with the Customer
rows.
A table that is normalized to the second normal form has these advantages:
2–11
Progress Database Design Guide
Order
Cust Num
Number Order Order Total After
(Foreign
(Primary Date Amount Tax
Key)
Key)
To reduce this table to third normal form, eliminate the Total After Tax column because it is a
dependent column that changes when the Order Amount or tax change. For your report, you can
create an algorithm to obtain the amount for Total After Tax. You need only keep the source
value because you can always derive dependent values. Similarly, if you have an Employee
table, you do not have to include an Age column if you already have a Date of Birth column,
because you can always calculate the age from the date of birth.
A table that is in third normal form gives you these advantages:
Although a database normalized to the third normal form is desirable because it provides a high
level of consistency, it may impact performance when you physically implement the database.
When this occurs, consider denormalizing these tables. Chapter 3, “Database Design Basics”
discusses denormalization.
2–12
3
Database Design Basics
Once you understand the basic structure of a relational database, you can begin the database
design process. Designing a database is an iterative process that involves developing and
refining a database structure based on the information and processing requirements of your
business. This chapter overviews each phase of the design process. The phases are:
• Data analysis
• Physical implementation
Progress Database Design Guide
Data Analysis
THE
Logical
Physical DATABASE
Data
Implementation DESIGN
Design
CYCLE
Physical Data
Design
• What types of information does my business currently use? What types of information
does my business need?
• What kind of information do I want from this system? What kind of reports do I want to
generate?
3–2
Database Design Basics
• What kind of data control and security does this system require?
To answer some of these questions, list all the data you intend to input and modify in your
database, as well as all the expected outputs. For example, some of the requirements a retail
store might include are the ability to:
• List alphabetically all the customers with outstanding balances of over $1,000
• List the total year-to-date sales and unpaid balances of all the customers in a specific
region
• List all orders for a specific item (for example, ski boots)
• List all items in inventory that have less than 200 units, and automatically generate a
reorder report
• Track customer information so you that have a current listing of customer accounts and
balances
• Track customer orders. Print customer orders and billing information for customers and
the accounting department
• Track inventory so you know which materials are in stock, which you need to order, where
they are kept, and how much of your assets are tied up with inventory
• Track customers’ returns on items so you know which items to discontinue or which
suppliers to notify
3–3
Progress Database Design Guide
Tables are generally grouped into three types — kernels, associations, and characteristics.
• Kernels are tables that are independent entities. They often represent or model things that
exist in the real world. Some examples are: customers, vendors, employees, parts, goods,
and equipment.
• Associations are talbes that represent a relationship among entities. For examples, an order
represents an association between a customer and goods.
• Characteritics are tables whose purpose is to qulify or describe some other entity. These
tables have no meaning in and of themselves, only in relation to the entity they describe.
For example, order-lines might describe orders; without an order, an order-line is useless.
The process of identifying the goals of the business, interviewing, and gathering information
from the different sources who are going to use the database is a time-consuming but essential
process. With the information in hand, you are now ready to define your tables and columns.
• Define the tables you need based on the information your business requires.
• Determine the primary keys and the column domain. A domain is the set of valid values
for each column. For example, the domain for the customer number may include all
positive numbers.
3–4
Database Design Basics
It is possible that at this stage you denormalize the database to meet performance requirements.
Denormalizing a database means that you re-introduce redundancy into your database in order
to meet processing requirements.
Let’s look at an example of when you might consider denormalizing a database. In Chapter 2,
“Table Relationships and Normalization,” you looked at the Order table, which is shown here
again in Table 3–1.
Order
Cust Num
Number Order Order Total After
(Foreign
(Primary Date Amount Tax
Key)
Key)
3–5
Progress Database Design Guide
To reduce the table to third normal form, you eliminated the Total After Tax column because it
contains data that can be derived. However, now you look at data access requirements. Although
you can construct the Total After Tax value, your customer service representatives need this
information immediately. Since this is an item of information that is constantly used, you don’t
want to have to calculate it each time you need it. If you keep it in the database, it is available
on request. In this instance, the performance outweighs other considerations.
3–6
4
Defining Indexes
This chapter explains what indexes are and when and why to define them.
Progress Database Design Guide
4.1 Overview
Like a book index, which helps a reader retrieve information on a topic quickly, a database table
index speeds up the process of searching and sorting rows. Although it is possible to search and
sort data without using indexes, indexes generally speed up data access. Use them to avoid or
limit row scanning operations and to avoid sorting operations. If you frequently search and sort
row data by particular columns, you might want to create indexes on those columns. Or, if you
regularly join tables to retrieve data, consider creating indexes on the common columns.
On the other hand, indexes consume disk space and add to the processing overhead of many data
operations—add, update, delete, copy, and move—including data entry, backup, and other
common administration tasks. Each time you update an indexed column, Progress updates the
index, and related indexes as well. When you create or delete a row, Progress updates each index
on the affected tables.
As you move into the details of index design, keep in mind that index design is not a once-only
operation. It is a process, and it is intricately related to your coding practices. Faulty code can
thwart any index scheme, and masterfully coded queries perform poorly if not properly
supported by indexes. Therefore, as the code develops, the indexing scheme—and other aspects
of your database design—may have to evolve as well.
Fortunately, index creation, modification, and deletion are all simple operations. Typically, you
create a database structure and a set of indexes that support expected access patterns. As the
application code develops, new access patterns might arise that require index support, or
particular queries might use indexes in unexpected ways, so you might have to modify indexes,
query code, or both. Intelligent query coding is outside the scope of this manual, but its
relevance to index design and creation cannot be overstated.
4–2
Defining Indexes
4–3
Progress Database Design Guide
In Figure 4–1, the rows of the Order table are physically stored in the sequence the user
enters them into the database. If you want to find a particular order number or order date,
the system must scan every individual row in the entire table until it locates the row(s) that
meet your selection criteria. Scanning is inefficient and time consuming where there are
hundred thousands or millions of rows in the table.
However, if you create an index on the Order Number column, Progress then stores the
order number values in sorted order (that is, 1, 2, 3, etc. ).
For example, when you query for order number 4, Progress does not go to the main table.
Instead, it goes directly to the Order-Num index to search for this value. Progress uses the
pointer to read the corresponding row in the Order table. Because the index is stored in
numerical order, the search and retrieval of rows is very fast.
Similarly, having an index on the date column allows the system to go directly to the date
value that you query (for example, 9/13/90). The system then uses the pointer to read the
row with that date in the Order table. Again, because the date index is stored in
chronological order, the search and retrieval of rows is very fast.
An index imposes an order on rows. Since an index automatically sorts rows sequentially
(instead of the order in which the rows are created and stored on the disk), you can get very
fast responses for range queries. For example, when you query, “Find all orders with dates
from 09/6/90 to 09/20/90", all the order rows for that range appear in chronological order.
NOTE: Although an index imposes order on rows, the data stored on disk is in the order in
which it was created. So, you can have multiple indexes on a table each providing a
different sort ordering, the physical storage order is not controlled by the indexes.
• Enforced uniqueness.
When you define a unique index for a table, the system ensures that no two rows can have
the same value for that index. For example, if order-num 4 already exists and you attempt
to create an order with order-num 4, you get an error message informing you that 4 already
exists. The message appears because order-num is a unique index for the order table.
4–4
Defining Indexes
Two tables are related if you define a column (or columns) in one table that you use to
access a row in another table. If the table you access has an index based on the
corresponding column, then the row access is much more efficient. The column you use
to relate two tables need not have the same name in both tables.
Index
Table Index Name Primary Unique
Column(s)
3. Ensuring that there is only one customer row for each customer
number (uniqueness).
name name NO NO
zip zip NO NO
1. Rapid access to all customers with a given zip code or in a zip code
range.
4–5
Progress Database Design Guide
Index
Table Index Name Primary Unique
Column(s)
3. Ensuring that there is only one item row for each item number
(uniqueness).
1. Ensuring that there is only one order-line row with a given order
number and line number. The index is based on both columns together
since neither alone need to be unique.
item-num item-num NO NO
4–6
Defining Indexes
Index
Table Index Name Primary Unique
Column(s)
3. Ensuring that there is only one order row for each order number
(uniqueness).
order-date order-date NO NO
4–7
Progress Database Design Guide
• Indexes take up disk space. (See the “Calculating Index Size” section.)
• Indexes can slow down other processes. When the user updates an indexed column,
Progress updates all related indexes as well. Also, when the user creates or deletes a row,
Progress changes all the indexes for that table.
Define the indexes that your application requires, but avoid indexes that provide minor benefit
or are infrequently used. For example, unless you display data in a particular order frequently
(such as by zip code), then you are better off sorting the data when you display it instead of
defining an index to do automatic sorting.
4–8
Defining Indexes
For example, if you have an index on a character column with an average of 21 characters for
column index storage (see Table 4–2) and there are 500 rows in the table, the index size is:
• The size of the column values, i.e. the character value “abcdefghi” takes more space than
“xyz”
However, you will never reach this maximum because Progress uses a data compression
algorithm to reduce the amount of disk space an index uses. In fact, an index uses on average
about 20% to 60% less disk space than the maximum amount you calculated using the
previously described formula.
The amount of data compressed depends on the data itself. Progress compresses identical
leading data as well as collapses trailing entries into one entry. Typically non-unique indexes
get better compression than unique indexes.
NOTE: All key values are compressed in the index, eliminating as many redundant bytes as
possible.
Table 4–2 lists the column storage values for different data types.
Date 3
4–9
Progress Database Design Guide
Decimal zero 1
Integer zero 1
1 2
128 3
32768 4
8 million 4
2,147,483,647 5
Logical false 0
true 1
4–10
Defining Indexes
4–11
Progress Database Design Guide
Because of the compression feature, Progress can substantially decrease the amount of space
indexes normally use. In the above example, 65 bytes are used to store the index that previously
took up 141 bytes. That’s a saving of approximately 54%. As you can see, the amount of disk
space saved depends on the data itself. You can save the most space on the non-unique indexes.
4–12
5
Progress 4GL Index Usage
Tag Meaning
ACCESS Indicates that the specified table and field value is used
at this point in the program.
An alternative method to determine index usage is to use the index statistics virtual system table.
The startup parameters that enable this are described in Chapter 4 of the Progress Database
Administration Guide and Reference.
5–2
Progress 4GL Index Usage
• At the end of a statement in which Progress assigns values to all components of the index
entry
• At the end of the closest iterating subtransaction block in which Progress 4GL creates the
record
Progress updates an index at the end of any statement in which it changes the values for one or
more index fields. Because Progress updates indexes immediately (at the end of an UPDATE
statement), Progress immediately FINDs records in the order of the new index, while the data
in the found record is unchanged. Progress changes the data in the record at the end of the scope
of the record or when it releases the record.
NOTE: Progress does not update an index if the value you try to assign to the index field is
the same as the current value of the index field.
You can change the name of an index at any time. You can also delete nonprimary indexes.
However, before letting you delete a primary index, Progress requires that you first designate
another index as primary.
If there is only one index, you must create a new index before deleting the existing index. You
cannot change any of the component definitions of an index. Instead, you must delete the index
and recreate it using the modified component definitions.
Remember that Progress assumes that the first index you create is the primary index, so create
your primary index first.
5–3
Progress Database Design Guide
r-sgn2.p
This procedure changes the order number and line number of an order-line record. (It copies an
order-line from one order to another.) It sets the new values into variables and modifies the
record with a single ASSIGN statement that contains two assignment phrases in the form
field=expression. So both fields are changed within a single statement. Because order-num and
line-num are used jointly in one index, this method avoids having the indexing done until both
values change.
5–4
Progress 4GL Index Usage
EXAMPLES
Example 1: using the sports database, the following query will display all records where
cust-num is > 10 because cust-num is an indexed field and the ? value will sort high in an
indexed field:
However, the query below will display ZERO records because cust-num is the chosen index for
the query. Since zip is not the chosen index, the ? value will not sort high and the second part
of the query will be false. No records are returned when one part of an AND is FALSE:
FOR EACH cust WHERE cust-num >10 AND cust-num <= ? AND zip >0 AND zip <?
Example 2: the same rule can affect queries where the ? value is not explicitly used. Using the
sports database, if you create three order records where order.cust-num = 1 and order-date = ?,
then the following query will return the three records:
5–5
Progress Database Design Guide
Case sensitivity is a characteristic of the field, not the index. Therefore, if an index contains
some fields that are case sensitive and some that are not, then the different sorting rules apply.
Field names are not case sensitive; they can be uppercase, lowercase, or a combination of both.
If you name a field “Phone” in the Dictionary, you can refer to it as “phone” or “PHONE” in
your procedures.
Ordinarily, Progress character fields are not case sensitive (“SMITH”=“Smith”=“smith”).
However, on rare occasions, you might want to define a field that is case sensitive. For example,
part numbers that contain both uppercase and lowercase characters should be stored in a
case-sensitive field. Case-sensitive fields are not recommended, because they depart from
standard Progress usage. However, if you require strict adherence to the ANSI SQL standard,
you might have to define all character fields as case sensitive. Once a field is defined as case
sensitive, you can change it back and forth, unless it is a component of an index. If a field is a
component of an index, you must delete the index, then re-create it using the modified field.
Case-sensitive fields can be indexed, and they can be grouped with case-insensitive field
components in an index. With case-sensitive indexes, “JOHN”, “John”, and “john” are all
unique values. However, sort order depends on the code page of your database. Note that you
can (and should) define case-sensitive variables to hold values moving to and from
case-sensitive fields. For more information on case sensitivity, see the ANSI SQL (-Q) startup
parameter in the Progress Startup Command and Parameter Reference.
SYNTAX
5–6
Progress 4GL Index Usage
For example:
SYNTAX
For example:
SYNTAX
For example:
The optional BY field clause imposes a sort order on returned records and is called a sort match.
A searchExpr typically has one of the following forms:
5–7
Progress Database Design Guide
For more information, see the Record Phrase and FOR statement reference entries in the
Progress Language Reference.
Because these expressions effectively select the records to return—and the indexes to use—they
are called search conditions. Commonly, but not always, field is an indexed field. Also, a
searchExpr can include other searchExpr’s joined by ANDs and ORs, forming arbitrarily
complex queries.
The Compiler constructs a logical tree from a query and evaluates both sides of each AND or
OR, looking for index criteria. Progress counts equality, range, and sort matches (for OR) and
uses them to select and bracket indexes. The precise rules are numerous and complex, and it is
not important to fully understand their details. The next sections outline the rules in sufficient
detail to help you develop a feel for index usage. In addition, you should experiment by coding
various queries, compiling them with the XREF option, and examining index usage as reported
in the SEARCH lines of the XREF output file.
The index selection examples that follow are based on the sports database.
If the searchExpr references a word-indexed field, Progress uses the word index.
If there is a BY field clause, and field is indexed, Progress uses the index to sort returned records
as long as there is no index on the WHERE clause. If field is not indexed, Progress creates a
temporary sort table and sorts the records at run time.
5–8
Progress 4GL Index Usage
If the selection criteria do not support multiple index usage, see the “General Rules for
Choosing a Single Index” section:
NOTE: If Progress uses multiple indexes to select and return records, the precise return order
is not predictable. If necessary, you can use the USE-INDEX or BY options to
guarantee record return order. In the following example, the BY clause guarantees
records are sorted by Cust-Num.
5–9
Progress Database Design Guide
In addition, if one side of the OR includes a CONTAINS clause (that is, it uses a word index),
Progress uses the word index and then a second index to satisfy the other side of the OR:
In this example, the right side of the OR includes a range match, but Postal-Code is the second
component of the County-Post index, so the match is not active. Progress uses the primary index
to satisfy this piece of the query and, as always, uses the word index to satisfy a CONTAINS
clause as shown in this example:
If the selection criteria do not support multiple index usage, see the “General Rules for
Choosing a Single Index” section.
NOTE: If any expression on either side of the OR does not use an index or all its’
components, Progress must scan all records using the primary index.
5–10
Progress 4GL Index Usage
1. If there is a CONTAINS clause (which is legal only for word indexed fields), use the word
index:
2. If an index is unique, and all of its components are used in active equality matches, use the
unique index. It invariably returns 0 or 1 records:
3. Use the index with the most active equality matches. Equality matches are active if:
AND
This disqualifies equality matches on, for example, components 2 and 3 of an index with
three components, and it disqualifies matches on components 1 and 2, if they surround an
OR:
5–11
Progress Database Design Guide
4. Use the index with the most active range matches. For a range match to be active it must
stand alone or be connected to other selection criteria by ANDs. In addition, it must apply
to an index component having any one of four properties:
• All preceding components in the index key have active equality matches
5. Use the index with the most sort matches. (All sort matches are active.)
5–12
Progress 4GL Index Usage
6. Use the index that comes first alphabetically. That is, if there is a tie—if multiple indexes
have the same number of active equality, range, and/or sort matches—use the alphabet to
decide:
5–13
Progress Database Design Guide
5.6.6 Bracketing
Having selected one or more indexes to satisfy a query, Progress tries immediately to isolate the
smallest necessary index subset, so as to return as few records as possible. This is called
bracketing. Careful query design can increase the opportunities for bracketing, thereby
preventing Progress from scanning entire indexes and examining all records. The rules for
bracketing are simple:
• Bracket an active range match, but no further brackets are possible for that index.
The following recommendations are intended to help you maximize query performance. They
are only recommendations, and you may choose to ignore one or more of them in specific
circumstances.
• Avoid ORs if any expression on either side of the OR does not use an index (or all its
components), be aware that Progress must scan all records using the primary index.
5–14
Progress 4GL Index Usage
• With word indexes, avoid using AND with two wildcard strings, either in the same word
index (WHERE comments CONTAINS “fast* & grow*”) or in separate word indexes
(WHERE comments CONTAINS “fast*” AND report CONTAINS “ris*”).
• Avoid WHERE clauses that OR a word index reference and a non-indexed criterion
(WHERE comments CONTAINS “computer” OR address2 = “Bedford”).
• A rule-of-thumb is fewer indexes per table with heavy update activity and limited access;
more indexes per table with heavy access but limited update activity.
• Most index processing—including, for example, all word index evaluations—takes place
on the Progress server side, and the minimum required records are returned to the client.
5–15
Progress Database Design Guide
5–16
6
Progress 4GL Word Indexes
Progress supports a type of index called a word index. A word index contains all the words from
a character field or array of character fields. Searching with this index makes it quick and easy
to locate records that contain specific words.
You can define a word index the same way you define any index from within the Data
Dictionary. The following sections describe the methods for defining word indexes using the
character and graphical Data Dictionary.
Progress Database Design Guide
This is the general syntax of the WHERE clause with the CONTAINS option:
SYNTAX
field
Refers to a character field or array on which a word index has been defined.
string-expression
Contains one or more words to search for in the character field field:
SYNTAX
word
A word to search for or a wildcard string. A wildcard string is any word that ends
with an asterisk (*). You can use a wildcard string to search for words that begin with
a specific initial substring. For example, the string “sales*” matches the words sales,
salesman, and salesperson.
& | | | ! | ^
Word separators. The ampersand (&)represents a logical AND; a vertical line (|),
exclamation point (!), or caret (^) represents a logical OR. Separators allows you to
limit your search to records that contain all words that you specify or to enlarge your
search to all records that contain any of the words you specify. You can combine
AND and OR operations within a string expression and group items with parentheses
to create complex search conditions.
6–2
Progress 4GL Word Indexes
EXAMPLE
The following example assumes that a word index has been defined on the Terms field of the
order table:
The AND operator (&) takes precedence over the OR operator (|). For this reason, the
parentheses in the preceding example are not required. They are used only to improve
readability.
EXAMPLE
This example finds all books whose description contains both the words “computer” and
“science”. If you omit both the ampersand and vertical line between two words (that is, the
words are separated only by spaces), a logical AND is assumed:
If your search condition specifies that the record must contain two or more specific words, the
order of the words is insignificant. In the previous example, a record containing the word
“science” and later the word “computer” may be displayed.
EXAMPLE
To find words in exact order, you can combine CONTAINS with the MATCHES function. In
this example, the words “computer” and “science” must appear in exact order, although another
word or words can appear between them:
EXAMPLE
You can combine other search criteria with a CONTAINS option. This example searches a table
that contains information about traffic accidents. It finds only records for accidents that
6–3
Progress Database Design Guide
occurred in Boston and contain the word “milk” and either the word “truck” or “trailer” in the
description field:
NOTE: Use the Stash Area (-stsh) startup parameter when you have a word index on a large
character field. For more information about this startup parameter, see the
description of the Stash Area (-stsh) startup parameter in the Progress Startup
Command and Parameter Reference.
6–4
Progress 4GL Word Indexes
• IGNORE — A character with this attribute is ignored when building the word index. Such
a character is never part of a key value.
• TERMINATOR — A character with this attribute ends a word and is never considered
part of a word.
• The LETTER attribute is assigned to all characters defined as letters in the current
language. In English, the uppercase characters A-Z and the lower-case characters a-z are
defined as letters.
• The following characters are assigned the USE_IT attribute: dollar sign ($), percent sign
(%), number sign (#), at symbol (@), and underline (_).
• The following characters are assigned the BEFORE_DIGIT attribute: period (.), comma
(,), and hyphen (-). This means, for example, “12.34" is one word, but “ab.cd” is two
words.
• The IGNORE attribute is assigned to the apostrophe (’). This means, for example, the
word John’s is the same as Johns.
These rules apply to both the text in a word index field and text in a CONTAINS clause. For
example, if you type “John’s” in a CONTAINS clause, it is treated the same as “Johns”. If you
type “8:30pm” it is treated as two words: 8 and 30pm. Therefore, a record containing the string
“8:30pm” will be found, but so could a record containing “8 Capital St. at 7:30pm.” As with
indexes, separators and terminators are ignored for the second part of the CONTAINS clause.
This means that the string entered in the database matches the string entered after the
CONTAINS clause.
6–5
Progress Database Design Guide
#define AT_SIGN 64
#define PERIOD 46
#define COMMA 44
word_attr =
{
PERIOD, BEFORE_DIGIT,
COMMA, BEFORE_DIGIT,
Ox2D, BEFORE_DIGIT, /*hyphen */
39, IGNORE, /*single quote */
’$’, USE_IT,
’%’, USE_IT,
’#’, USE_IT,
AT_SIGN, USE_IT,
’_’ USE_IT
};
Note that you can use the #define syntax to define constants. Within the word_attr definition
you can reference characters by enclosing them in single quotes (‘ ’), by their decimal ASCII
values, or by their hexadecimal values (0x2D, for example). Each item in the table except the
last item must be followed by a comma.
Your word-break table does not have to include every character. By default, all letters in the
language are assigned the LETTER attribute, the characters 0 through 9 are assigned the DIGIT
attribute, and all other characters are assigned the TERMINATOR attribute. You only have to
specify the characters whose attributes you want to change.
NOTE: The asterisk (*), vertical line (|), exclamation point (!), caret (^), and opening and
closing parentheses all have special meaning within a CONTAINS clause. You must
give these characters the TERMINATOR attribute or their special meaning is lost.
You may, however, select to maintain only one of the OR operators and use the
others as letters.
After you’ve defined your word-break table, you must compile it with the PROUTIL command:
Operating Syntax
System
6–6
Progress 4GL Word Indexes
In the syntax, database is the name of your database, src-file is the name of your word-break
rules file, and rule-numb is a number between 1 and 255 that uniquely identifies this set of rules
on your system.
The PROUTIL command produces a binary file named prowrd.rule-numb. For example, if
rule-numb is 34, the file is named prowrd.34. To reference this file, you must either move it to
the $DLC directory or set the environment variable PROWDrule-numb to reference it. For
example, the variable PROWD34 specifies the location of the prowrd.34 file. (Note that the
PROWD environment variable does not contain a period.)
To apply word-break rules to a database, use the word-rules qualifier of the PROUTIL
command:
Operating Syntax
System
The value of rule-numb is the same value you specified when compiling the rules. To switch
back to the default rules, specify 0 for rule-numb.
If you change the word-break rules when word indexes are active, the indexes might not work
properly because the rules used to create the index differ from those used when searching the
index. Therefore, when you change the break rules for a database, Progress warns you if any
word indexes are active. You should rebuild these indexes. You can make old indexes consistent
with the new rules by rebuilding them with the PROUTIL idxbuild qualifier. For more
information about the PROUTIL idxbuild qualifier, see the PROUTIL idxbuild qualifier entry
in the Progress Database Administration Guide and Reference.
Progress maintains a cyclic redundancy check (CRC) to ensure that the word-break rule file
does not change between sessions. If it has changed, Progress displays a message when you
attempt to connect to the database. The connect attempt fails. You can fix this by restoring the
original file or resetting the break rules to the default. Note that resetting to the default break
rules may invalidate your word indexes.
6–7
Progress Database Design Guide
REPEAT:
UPDATE words.
FOR EACH line WHERE line_text CONTAINS words:
DISPLAY line.
END.
END.
The example prompts for a string of words and then displays each line that matches the search
criteria.
6–8
Progress 4GL Word Indexes
6–9
Progress Database Design Guide
6–10
7
Constraints and Indexes Using SQL-92
This chapter explains what constraints and indexes are and why to define them.
Progress Database Design
7.1 Constraints
You can achieve data integrity with constraints, or rules, using SQL-92 contructs on your keys.
Constraints can be named at the column or table level.
7.1.1 Keys
There are two types of keys: primary and foreign.
A primary key is a column (or group of columns) whose value uniquely identifies each row in
a table. Because the key value is always unique, you can use it to detect and prevent duplicate
rows. You can have only one primary key per table. Primary keys may be referenced by other
tables. There can be only one primary key for a table. For more information on criteria for
choosing a primary key refer to Chapter 1, “Introduction.”
A foreign key is a column of data that is common to more than one table (and it is the primary
key of one of these tables). It is this relationship of a column in one table to a column in another
table that provides the relational database with its ability to join tables. Chapter 2, “Table
Relationships and Normalization,” describes this concept in more detail.
When using SQL-92, you create your keys when you create your table. For information on the
SQL CREATE TABLE command see the Progress SQL-92 Guide and Reference.
7–2
Constraints and Indexes Using SQL-92
7.2 Indexes
An index is a “b-tree” that corresponds with a data table. For every row in the data table there
is a corresponding row in the index table. Records in the index are always sorted.
The best time to create an index is the same time you are creating the table. It is important to
anticipate the ways in which you may want to access the data and create indexes to
accommodate that.
A primary index is an index on a primary key. A secondary index is an index on a key that is
not the primary key in the table. An index can be unique.
An index has these advantages:
• Faster row search and retrieval. It is more efficient to locate a row by searching a sorted
index table than by searching an unsorted table.
• Records are ordered automatically to support your particular data access patterns. No
matter how you change the table, when you browse or print it, the rows appear in indexed
order instead of their stored physical order on disk.
• When you define an index as unique, each row is unique. This ensures that duplicate rows
do not occur.
• A combination of columns can be indexed together to allow you to sort a table in several
different ways at once (for example, sort the Projects table by a combined employee and
date column).
To create an index in SQL-92 use the CREATE INDEX statement. This statement will create
an index on the table you specify using the specified columns of the table. For more information
on the CREATE INDEX statement see the Progress SQL-92 Guide and Reference.
You may create a unique index by creating the index on the primary key. A unique index does
not allow the table to contain any rows with duplicate column values for the set of columns
specified for the index.
A secondary index may be created on a key that is not primary.
7–3
Progress Database Design
• If you specify an index as UNIQUE and all values in the existing rows are not unique,
an error message is returned and the index is not created.
7–4
8
Progress 4GL Triggers
A database trigger is a block of 4GL code that executes whenever a specific database event
occurs. A database event is an action preformed against the database.
This chapter discusses Progress 4GL triggers.
Progress Database Design
8.2.1 CREATE
When Progress executes a CREATE or INSERT statement for a particular database table,
Progress creates the record, then fires all applicable CREATE triggers, then fires all
applicable REPLICATION-CREATE triggers.
8.2.2 DELETE
When Progress executes a DELETE statement for a particular database table, Progress
fires all applicable DELETE triggers, then fires all applicable REPLICATION-DELETE
triggers, then validates the delete, then performs the delete.
8–2
Progress 4GL Triggers
8.2.3 FIND
When Progress reads a record in a particular database table using a FIND or GET
statement or a FOR EACH loop, Progress fires all applicable FIND triggers. FIND triggers
fire only for records that completely satisfy the full search condition, such as a WHERE
clause specifies. FIND triggers do not fire in response to the CAN-FIND function.
Note that if a FIND trigger fails, Progress behaves as though the record had not met the
search criteria. If the FIND is within a FOR EACH block, Progress simply proceeds to the
next record. If your application uses the BREAK option of the PRESELECT phrase
(which forces Progress to retrieve two records at a time, so it can find the break), Progress
executes the FIND trigger twice during the first FIND, which is actually two FINDs in
succession. Thereafter, Progress looks one record ahead of the record currently in the
record buffer, and executes the FIND trigger before it places the next record in the buffer.
8.2.4 WRITE
When Progress changes the contents of a record and validates it for a particular database
table, Progress first fires all applicable WRITE triggers, then fires all applicable
REPLICATION-WRITE triggers. Progress automatically validates a record when
releasing it. You can also use the VALIDATE statement to explicitly validate a record. In
either case, WRITE triggers execute before the validation occurs (so WRITE triggers can
correct values and do more sophisticated validation). Progress might execute the WRITE
triggers for a single record more than once before it writes the record to the database (if it
validates the record more than once and you modify the record between validations).
8.2.5 ASSIGN
When Progress updates a particular field in a database record, Progress fires all applicable
ASSIGN triggers. Unlike the other database events, this one monitors a specific field
rather than a table. ASSIGN triggers execute when the contents of the associated field are
modified. The trigger procedure executes at the end of a statement that assigns a new value
to the field and after any necessary re-indexing. If the statement contains several field
assignments (for example, UPDATE name city st), Progress fires each applicable
ASSIGN trigger at the end of the statement. If any trigger fails, Progress undoes the
statement (unless the code specifies NO-UNDO). For more information on
replication-related triggers and database replication, see the Progress Database
Administration Guide and Reference.
8–3
Progress Database Design
8–4
Progress 4GL Triggers
8–5
Progress Database Design
that ASSIGN trigger executes. You must carefully design your triggers to avoid conflicts. For
example, trigger A could change data, which could cause trigger B to execute. Trigger B could
change the same data, a change you did not anticipate or want.
NOTES
• To ensure integrity, you must have both types of triggers, or use SQL to only read data, or
have only SQL table.
8–6
9
Java Stored Procedures and Triggers
A Java stored procedure is a group of SQL-92 statements that form a logical unit and perform
a particular task. Stored procedures are used to encapsulate a set of operations or queries for
execution on a database server.
A trigger is a special type of stored procedure that is automatically invoked when certain
database events occur. Triggers are used to enforce referential integrity and business rules.
This chapter discusses stored procedures and triggers.
Progress Database Design Guide
9–2
Java Stored Procedures and Triggers
Designing the trigger code consists of writing the Java code that defines what the application
does when the user interacts with the user-interface elements. For example, the application
might write a particular database record when the user clicks on a particular button. In this case,
the trigger code is the code that writes the record when the user clicks on that button.
Java triggers execute on the database server side.
Cascading Updates
An update operation on one table causes additional rows to be updated in other tables that are
related to the first table by key values. These updates are commonly limited to the key fields
themselves. This is an active way to enforce referential integrity that a table constraint enforces
passively.
Summation Updates
An update operation in one table causes an update operation in a row of another table. The
second value is increased or decreased.
Automatic Archiving
A delete operation on one table creates an identical row in an archive table that is not otherwise
used by the database.
9–3
Progress Database Design Guide
EXAMPLE
The following code illustrates an example of a statement trigger:
NOTE: The UPDATE statement executes only once regardless of how many rows are
deleted.
EXAMPLE
The following code examples illustrates a row trigger:
NOTES
• The INSERT statement executes once for each record inserted into the customer table.
• In order for a trigger to work, you cannot use a FOREIGN KEY restriction in the table
definition.
9–4
Java Stored Procedures and Triggers
Additionally, if you need both 4GL and SQL access to your triggers, you must create both.
Restrictions
The actions in a Java database trigger are restricted. Java triggers:
When the trigger event (INSERT, UPDATE or DELETE) affects the target table, the
Java code contained in the body of the trigger executes. A stored procedure must be
explicitly invoked by an application or another procedure.
Since triggers are automatic, there is no calling application to process any output they
might generate.
The only possible input parameters for triggers are values of columns in the rows
affected by the trigger event.
9–5
Progress Database Design Guide
Constraints are passive. While constraints prevent updates that violate referential
integrity, triggers perform explicit actions in addition to the update operation.
Because they are passive, constraints are limited to preventing updates within a
narrow set of conditions. Triggers are more flexible. However, performance may
suffer.
9–6
Index
A schema 1–10
Databases
Audience xi
advantages 1–3
computerized 1–3
B defined 1–2, 2–5
indexing 4–1, 4–3
Bold typeface noncomputerized 1–2
normalization 2–6
as typographical convention xii
C E
Error messages
Case-sensitivity
displaying descriptions xvii
field names 5–5
indexes 5–6
Columns F
defined 1–5
Fields 1–5
Compound indexes 1–7 defined 1–5
foreign keys 2–2
CONTAINS 6–3
Foreign keys 2–2
Cross-reference tables- 2–5
H
D
Help
database Progress messages xvii
metaschema 1–10
Progress Database Design
Indexes 1–6
advantages 4–4
N
case-sensitive indexing 5–5
Normalization 2–6
choosing tables and fields to index 4–8
compound 1–7 first normal form 2–6
deactivating 4–12 second normal form 2–9
defined 1–6 third normal form 2–11
defining 4–1
demo database 4–5
disk space 4–9
O
how indexes work 4–3
maintaining 5–3 One-to-many table relationships 2–4
reasons not to define 4–8 One-to-one table relationships 2–3
record ID 4–8
redundant 4–12, 5–2
selecting best 5–6 P
size 4–9
unknown values 5–4 Primary keys 1–6, 7–2
using ASSIGN 5–4
Italic typeface
as typographical convention xii
R
Record ID 4–8
K Records
defined 1–5
Keystrokes xiii
Rows
defined 1–5
M
Manual S
organization of xi
syntax notation xiii Syntax notation xiii
Many-to-many relationships 2–4
MATCHES 6–3 T
Messages Table relationships
displaying descriptions xvii many-to-many 2–4
one-to-many 2–4
Monospaced typeface one-to-one 2–3
Index–2
Index
Tables W
cross-reference 2–5
defined 1–5 Word delimiters. See Word index
normalization
first normal form 2–6 Word indexes
second normal form 2–9 default rules 6–5
third normal form 2–11 defining
relationships 2–2 on external documents 6–7
delimiters
Typographical conventions xii defining 6–6
description 6–1
word delimiters 6–4
U
Word-break
Unknown value applying rules file to a database 6–7
indexes 5–4 compiling 6–7
defined 6–6
Index–3
Progress Database Design
Index–4