Aracılığıyla paylaş


How to: Associate Tables with a Database

After you create a database, you can associate tables with a database by creating them in the database or adding existing ones. Tables can belong only to one database at a time; therefore you can associate any table that is not currently part of another database. If you want to associate a table that belongs to another database, you must remove that table before you can add it to a different database. You can also use data from another database table without removing it. For more information, see How to: Use Tables from Other Databases.

Note

To associate free tables with a database, you must explicitly add them. Modifying their structure does not associate free tables with a database, even if a database is open when you modify the structure.

When you add a table to a database, Visual FoxPro modifies the header record in the table file to document the path and file name for the database that now contains the table. This path and file name information is called a back link because it links the table back to the owning database.

To create database tables, see How to: Create Database Tables.

To associate a table with a database

  1. Open the database in the Database Designer.

    The Database menu appears.

  2. On the Database menu, click Add Table.

  3. In the Open dialog box, browse for and select a table, and click OK.

    The table you selected appears in the Database Designer.

To associate a table with a database in a project

  1. Open the project in the Project Manager.

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

  3. Click the Tables node, and then Add.

  4. In the Select table name dialog box, browse for and select the table (.dbf) file you want to add, and click OK.

    The table you selected appears in the Tables node of the Project Manager.

For more information, see Project Manager Window.

To associate a table with the current database programmatically

  1. Open the database.

  2. Use the ADD TABLE command.

    For example, the following code opens a database named MyDatabase and adds a table called MyTable:

    OPEN DATABASE MyDatabase
    ADD TABLE MyTable
    

For more information, see ADD TABLE Command.

See Also

Tasks

How to: Open Tables (Visual FoxPro)

How to: Open Databases

Reference

Databases in Visual FoxPro

Other Resources

Creating Databases

Working with Items in Databases