INSERT Acts Like APPEND on Indexed Database

ID: Q96339

The information in this article applies to:

SUMMARY

In Microsoft FoxPro, the INSERT command is used to insert a record into the current database file immediately after the current record. However, when you are attempting to insert a record in a database that has an open index file, the INSERT command will work like the APPEND command and add the new record to the end of the database file. This behavior occurs even if the database is not ordered by any of the indexes in the open index file.

MORE INFORMATION

The INSERT command is included in FoxPro primarily for backward compatibility. The APPEND command should be used if possible and the order of the database can then be set using an index.

If the actual physical order of the data in the .DBF file is important, the SET INDEX TO command can be used without any additional arguments to close all open index files (except a structural .CDX file) in the current work area. The INSERT command can then be used to insert data in the desired order.

If the database has a structural .CDX index file, however, the INSERT command will always act like the APPEND command because a structural .CDX file is opened automatically when the database is opened. In order to use the INSERT command on a database with a structural .CDX file, all the index tags in the structural .CDX file must first be removed. They can then be recreated in a nonstructural .CDX file (with a different name from that of the .DBF file) which will not be automatically opened with the database.

REFERENCES

"Commands & Functions," version 2.0, INSERT command

"Language Reference," version 2.5, INSERT command

Additional reference words: FoxDos FoxWin 2.00 2.50 2.50a KBCategory: kbprg KBSubcategory: FxprgGeneral

Last Reviewed: June 27, 1995