Condividi tramite


Working with Multiple Tables

To use multiple tables, you use data sessions to control the tables that are available to forms, and work areas to set which tables are open. A work area is a numbered region that identifies an open table. You can open and manipulate Visual FoxPro tables in 32,767 work areas. Work areas are normally identified in your application by using the table alias of the table open in the work area. A table alias is a name that refers to a table open in a work area.

Using Data Sessions

In addition to the work areas visible in the Data Session window, Visual FoxPro automatically provides a separate environment for each instance of a form or form set through data sessions. A data session is a representation of the current dynamic work environment used by a form, form set, or report. Each data session contains its own set of work areas. These work areas contain the tables open in the work areas, their indexes, and relationships. For information on using data sessions, see Programming for Shared Access.

Viewing Work Areas

You can see the list of tables open in a Visual FoxPro session by opening the Data Session window.

To open the Data Session window

  • From the Window menu, choose Data Session.

    -or-

  • Use the SET command.

When you enter SET in the Command window, Visual FoxPro opens the Data Session window and displays the work area aliases for the tables open in the current data session.

Opening a Table in a Work Area

You can open a table in a work area with the Data Session window or with the USE command.

To open a table in a work area

  • In the Data Session window, choose Open.

    -or-

  • Type USE in the Command window.

To open a table in the lowest available work area, use the IN clause of the USE command with work area 0. For example, if tables are open in work areas 1 through 10, the following command opens the customer table in work area 11.

USE customer IN 0

You can also choose Open from the File menu to open a table in a work area.

Closing a Table in a Work Area

You can close a table in a work area through the Data Session window or by using the language.

To close a table in a work area

  • From the Data Session window, select the alias of the table, and then choose Close.

    -or-

  • Type USE without a table name.

    -or-

  • Use the IN clause of the USE command to reference the work area of the table you want to close.

When you issue the USE command without a table name and a table file is open in the currently selected work area, the table is closed. For example, the following code opens the customer table, displays a Browse window, and then closes the table:

USE customer 
BROWSE
USE

You also close a table automatically when you open another table in the same work area, or issue the USE command with the IN clause and reference the current work area. The following code opens, displays, and then closes the customer table by issuing USE IN and the table alias customer:

USE customer 
BROWSE
USE IN customer

You can't have more than one table open in a work area at one time.

Referencing a Work Area

You can reference the next available work area before you open a table by using the work area number as shown below:

SELECT 0

See Also

Enhancing the Efficiency of Indexes | Working with Table Aliases | Working with Records | Setting Temporary Relationships Between Tables | Establishment of Persistent Relationships with Indexes | Ordering by Multiple Fields