Partager via


Adding Tables to a Database

Begin building your database by adding the tables you want to use. You can select any table that is not currently part of another database. Since tables can only belong to one database at a time, you need to remove a table from a database before you can use it in a new database.

To add a table to a database

  1. From the Database menu, choose Add Table.
  2. In the Open dialog box, select a table and choose OK.

Free Tables and Database Tables

Each Visual FoxPro table can exist in one of two states: either as a free table, which is a .dbf file that is not associated with any database, or as a database table, which is a .dbf file that is associated with a database. Tables associated with a database can have properties that tables outside a database do not have, such as field-level and record-level rules, triggers, and persistent relationships.

You associate tables with a database by creating them within an open database, or by adding existing tables to a database. For more information, see Working with Tables.

To add a free table to a database

  • In the Project Manager, select Tables from the All tab or the Data tab, then choose Add.

    -or-

  • Use the ADD TABLE Command.

For example, the following code opens the testdata database and adds the orditems table:

OPEN DATABASE testdata
ADD TABLE orditems

You must explicitly add an existing free table to a database to make it a part of a database. Modifying the structure of a free table does not cause Visual FoxPro to add the free table to a database, even if a database is open when you issue the MODIFY STRUCTURE command.

Using Free Tables

You can associate a given table with only one database. However, you can use the data in an existing .dbf file without incorporating it into your database.

To access a table in another database

  • Create a view in your database that references the table.

    -or-

  • Access the table with the USE command and the "!" symbol.

Use the "!" symbol to refer to a table in a database other than the current database. For example, if you want to browse the orditems table in the testdata database, you can type:

USE testdata!orditems
BROWSE

In the previous example, the testdata database is opened automatically for you when you issue the USE command, but Visual FoxPro does not set testdata as the current database. A database opened automatically, as in the previous example, is automatically closed when the table is closed, unless you open the database explicitly before closing the table.

For more information, see Creating Views.

See Also

Creating a Database | Removing a Table from a Database | Updating Table and Database Links | Creating Persistent Relationships | ADD TABLE | Designing Databases | Developing Databases | Working with a Database