次の方法で共有


How to: Remove a Table from a Database

You can remove a table from the database or delete the table from disk permanently. Removing a table from a database does not delete the table automatically. However, it removes the table and associated data dictionary information from the database file and also updates the back link information to reflect the new status of the table as a free table.

Note

You must first close a table before removing or deleting it. If a database table has a long name, removing the table from the database also removes the long name. For more information, see How to: Name Tables.

To remove or delete a table in a database

  1. Open the database in the Database Designer.

  2. In the Database Designer, click the table you want to remove.

  3. On the Database menu, click Remove.

    Visual FoxPro prompts you to remove the table from the database or delete it from disk.

  4. In the confirmation dialog box, perform one of the following:

    • To remove the table, click Remove.

    -OR

    • To delete the table from disk, click Delete.

To remove or delete a table from a database in a project

  1. Open the project in the Project Manager.

  2. In the Project Manager, expand the Data node, the Databases node, then the Tables node.

  3. Click the table you want to remove, and then Remove.

    Visual FoxPro prompts you to remove the table from the database or delete it from disk.

  4. In the confirmation dialog box, perform one of the following:

    • To remove the table, click Remove.

    -OR

    • To delete the table from disk, click Delete.

To remove or delete a table from the current database programmatically

  • Perform one of the following:

    • To remove the table from the database, use the REMOVE TABLE command.

      -OR-

    • To delete the table from disk, use the DROP TABLE command or use the REMOVE TABLE command with the DELETE clause.

For more information, see REMOVE TABLE Command and DROP TABLE Command.

For example, the following code opens a database named MyDatabase without opening the Database Designer and removes a table named MyTable:

OPEN DATABASE MyDatabase
REMOVE TABLE MyTable

The following code opens a database named MyDatabase without opening the Database Designer and deletes a table named MyTable from disk:

OPEN DATABASE MyDatabase
REMOVE TABLE MyTable DELETE

The following code opens a database named MyDatabase without opening the Database Designer and deletes a table named MyTable from disk without moving the file to the Windows Recycle Bin:

OPEN DATABASE MyDatabase
DROP TABLE MyTable NORECYCLE

Warning

Do not use the ERASE command with tables associated with a database. ERASE does not update the back link to the database and can cause table access errors.

See Also

Tasks

How to: Open Databases

How to: Update Table and Database Links

Other Resources

Creating Databases

Working with Items in Databases