Replaces data in the specified fields of the current table with data from another table.

Syntax

UPDATE ON <key field> FROM <alias>
REPLACE <field 1> WITH <exp 1>
  [, <field 2> WITH <exp 2>...]
[RANDOM]
[REINDEX]

<key field>

The key field that is common to both the current table and the table containing the updated information.

FROM <alias>

The work area that provides updates to the current table.

REPLACE <field 1>

The field in the current table to be updated with data from the table specified by FROM <alias>.

WITH <exp 1>

The expression to store in field <field 1>. Use the FROM table’s alias name and the alias operator (that is, alias->field) to refer to field values in the FROM table.

[ ,<field n> WITH <exp n> ...]

Specifies additional fields to be updated.

RANDOM

Specifies the FROM table is neither indexed nor sorted. (The current table must be indexed on the key field common to both tables.)

REINDEX

Rebuilds open indexes after all records have been updated. Without REINDEX, dBASE Plus updates all open indexes after updating each record. When the current table has multiple open indexes or contains many records, UPDATE executes faster with the REINDEX option.

Description

The UPDATE command uses data from a specified table to replace field values in the current table. It makes the changes by matching records in the two files based on a single key field.

The current table must be indexed on the field in the key field. Unless the RANDOM option is used, the table in the specified work area should also be indexed or sorted on the same field. The key fields must have identical names in the two tables.

UPDATE works by traversing the FROM table, finding the matching record in the current table (the current table must be indexed or sorted so that the match can be found quickly), and executing the REPLACE clause. If there is no match for a record in the FROM table, it is ignored. If there are multiple records in the FROM table that match a single record in the current table, all the replacements will be applied. For a simple REPLACE clause, only the last one will appear to have taken effect.

SET EXACT affects the matching, so if you are using a language driver with both primary and secondary weights (not U.S. language drivers but most others) you should have SET EXACT ON.

OODML

Use the update( ) method of an UpdateSet object. Unlike the UPDATE command, the update( ) method updates all, rather than selected, fields in a row.