How to: Delete Indexes

By deleting indexes, or index tags, that you never use, you can improve performance by removing the need for Visual FoxPro to update those tags. To delete an index, delete the index tag in the compound index (.cdx) file or delete the entire standalone index (.idx) file.

You can delete index tags in structural .cdx files by using the Visual FoxPro IDE or language. To delete an .idx file or index tags from a nonstructural .cdx file, use the Visual FoxPro language.

Deleting Index Tags from a Structural .cdx File

You can delete an index tag from the structural .cdx file by using the Table Designer, the DELETE TAG command if you know the tag name, or the SQL ALTER TABLE command if you do not know the tag name but you know the tag is a primary or unique index.

To delete an index tag in a structural .cdx file

  1. Open the Table Designer to modify your table and choose the Indexes tab.

  2. Select the index and choose Delete.

    For more information, see Table Designer (Visual FoxPro).

-OR-

  • Use the DELETE TAG command.

    For example, suppose the structural .cdx file for the Employee table in the Visual FoxPro sample database, TestData, contains an index tag named Title. The following code deletes the Title index tag:

     CopyCode imageCopy Code
    USE Employee
    DELETE TAG Title

    To delete all the tags in the .cdx file, include the ALL clause in the DELETE TAG command. For more information, see DELETE TAG Command.

-OR-

  • Use the DROP PRIMARY KEY or DROP UNIQUE TAG clause in the SQL ALTER TABLE command.

    For example, suppose the index tag you wanted to delete is the primary key for the Employee table in the sample database, TestData, but you did not have the name of the index key. You can use the DROP PRIMARY KEY clause in the SQL ALTER TABLE command:

     CopyCode imageCopy Code
    USE employee
    ALTER TABLE DROP PRIMARY KEY

    For more information, see ALTER TABLE - SQL Command.

Deleting Index Tags from a Nonstructural .cdx File

You cannot view the index tags in nonstructural .cdx files in the Table Designer. Therefore, you must know the name of the index tag and use the DELETE TAG command to delete an index tag from a nonstructural .cdx file.

To delete an index tag in a nonstructural .cdx file

  • Use the DELETE TAG command and the OF clause to specify the name of the tag and the .cdx file that you want to delete the index tag from.

    For example, suppose you have a nonstructural .cdx file named QRTLYRPT.CDX containing a tag named Title. The following line of code deletes the Title tag:

     CopyCode imageCopy Code
    DELETE TAG Title OF QRTLYRPT

    To delete all the tags in the .cdx file, use the ALL clause in the DELETE TAG command. For more information, see DELETE TAG Command.

Deleting Standalone .idx Files

A standalone index (.idx) file contains only a single index key expression; therefore, you can delete the index by deleting the .idx file.

To delete a standalone .idx file

  • Use the DELETE FILE command.

    For example, suppose you have a standalone .idx file called OrdDate.idx. The following line of code deletes the .idx file:

     CopyCode imageCopy Code
    DELETE FILE OrdDate.idx

    For more information, see DELETE FILE Command.

You can also use your computer operating system to delete the file.

See Also


© , 1996-2020 • Updated: 11/10/20
Comment or report problem with topic