[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
+---------------------------------+
|              INDEX              |
+---------------------------------+
INDEX ON <expr> TO <.idx file>
        | TAG <tag name>
        [OF <.cdx file>]
        [FOR <expL>]
        [COMPACT]
        [ASCENDING | DESCENDING]
        [UNIQUE]
        [ADDITIVE]

-----------------------------------
Creates an index file to order a database.
-----------------------------------

INDEX is used to create an INDEX file or tag for the currently selected
database.  A database that has an index file is displayed and accessed
in the order specified by the index expression <expr> as long as order
is set to the index.  The physical order of the records in the database
file isn't changed by an index file.

If TALK is SET ON, FoxPro reports how many records have been indexed
during the indexing process.  The record interval displayed during
indexing may be specified with SET ODOMETER.

DISPLAY STATUS gives extensive information about open index files.  This
information includes the names of all open index files, their types
(structural, .CDX, .IDX), their index expressions and the name of the
master index file or master tag.

The number of index files (.IDX or .CDX) you can open is limited only by
memory and the total number of files you can open.  The number of files
you can open is determined by the FILES setting in the DOS CONFIG.SYS
configuration file.  See your DOS manual for more information on the DOS
FILES setting.

Index Types
-----------

FoxPro lets you create two types of index files:

        . Compound .CDX index files containing multiple index entries called
tags

        . .IDX index files containing one index entry

A structural compound index file can be created.  Structural compound
index files are automatically opened with the database file.

Because structural .CDX index files are automatically opened when the
database is opened, they are the preferred index type.

Include COMPACT to create compact .IDX index files.  .CDX index files
are always compact.

If you are sharing files between FoxPro and FoxBASE+ or FoxBASE+/Mac,
you must use non-compact .IDX index files.  Otherwise, if you build .IDX
files always include COMPACT to benefit from FoxPro 2.0's faster access
index technology.

Index Order and Updating
------------------------

Only one index file (the master index file) or tag (the master tag)
controls the order in which the database is displayed or accessed.
Certain commands (SEEK for example) use the master index file or tag to
search for records.  However, all open .IDX and .CDX index files are
updated as changes are made to the database.  You may designate the
master index file or tag in the INDEX clause of USE or with SET INDEX
and SET ORDER.  See each of these commands in this help facility for
additional information on setting a master index file or master tag.

User-defined Functions
----------------------

The index expression can contain a user-defined function (UDF).  Care
should be exercised when referencing a UDF in an index expression.

Referencing a user-defined function in an index expression will increase
the time it takes to create the index.

A UDF could be used to extract the street name from a single database
field where both the street number and street name are included.
Assuming the street number is always numeric, the UDF could return the
character portion of the field and pad it with spaces as needed to
create a constant length index key.  The database could then be accessed
in street name order.

FoxPro must be able to locate the UDF included in an index expression to
update the index.  When FoxPro creates an index, the index expression is
saved in the index file, but only a reference to the UDF is included in
the index expression.

Clauses
-------

<expr>
        The index expression <expr> includes fields from the currently selected
database.  An index key based on the index expression is created in the
index file for each record in the database.  FoxPro uses these keys to
display and access records in the database.  For compound indexes, the
length of the index expression plus the length of the FOR clause (if
any) cannot exceed 254 characters.  The length of the index expression
cannot exceed 100 characters for single index files (IDX files).

TO <.idx file>
        An .IDX index file can be created by including the TO <.idx file>
clause.  To create a compact .IDX index file include COMPACT.  The index
file created is given a default extension of .IDX, which may be
overridden by explicitly including a different extension, or by changing
the default index extension in the CONFIG.FP configuration file.
Standard DOS rules for naming files must be observed when creating index
files.

TAG <tag name> [OF <.cdx file>]
        A .CDX compound index file may be created by including  TAG <tag name>.
A .CDX compound index file is a single index file that can consist of
any number of separate tags (index entries); each tag is identified by
its unique <tag name>.  Tag names, like memory variables, must begin
with a letter or an underscore and may consist of any combination of up
to 10 letters, digits or underscores.  The number of tags in a .CDX
compound index file is limited only by available memory and disk space.

        Multiple-entry compound index files are always compact.  It isn't
necessary to include COMPACT when creating a compound index file.
Compound indexes are given a .CDX extension.

        Two types of .CDX compound index files may be created.  The first type,
a structural compound index file, is created when you include TAG <tag
name> without including the optional OF <.cdx file> clause.  Structural
.CDX files always have the same base name as the database.  A structural
compound index file is automatically opened every time the database is
opened.

        If a database's structural index file cannot be located or has been
deleted or renamed, the dialog "Structural CDX file not found" is
displayed when you try to open the database file.  If you choose the
default Cancel push button the database isn't opened.  Choosing Ignore
opens the database and removes the flag in the database's header which
indicates an associated structural index file is present.

        To reassociate a structural index that has become dissociated from its
database, issue the command

        USE <file> INDEX <file>

        The next time you open the database the structural index is opened too.
Note, if the database has been modified since the structural index was
dissociated, be sure to reindex.

        A non-structural compound index file may be created by including OF
<.cdx file> after TAG <tag name>.  Unlike a structural compound index
file, a non-structural compound index file must be explicitly opened
with SET INDEX or the INDEX clause of the USE command.

        If a compound index file has already been created and opened, issuing
INDEX with TAG <tag name> adds a tag to the compound index file.  If a
compound index file hasn't been created, one is automatically created.

FOR <expL>
        FOR <expL> may be included to make an index file act as a filter on the
database.  Only records that match the filter expression are available
for display and access -- index keys are created in the index file for
just those records matching the filter expression.

This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson