View Creation

The basic process for creating a view is generally the same regardless of the method you use and the type of view you create:

  1. Determine the type of view you need to create.

  2. Specify the tables or views you want to retrieve records from and their join conditions.

  3. Select the fields you want to retrieve data from.

  4. Specify any additional criteria for retrieving records from those tables.

  5. Specify whether to update the original tables or base tables used to build the view.

  6. Generate the view to retrieve and view the resulting records.

Similar to queries, when you create a view, Visual FoxPro builds and runs a SQL statement that defines the data set for the view using the view definition you created. You can also set properties for views.

Combining Views

You can combine views when need a subset of data from other views or if you want to combine local and remote data in a single view. A view built from other views is called a top-level view. A view built from local tables and local or remote views is called a multitiered view.

The basic process for combining local and remote data into a single view is described in the following steps:

  1. Create a remote view.

  2. Create a local view and add the remote view you created.

  3. Add any local tables that you want to the local view and join them on a common field.

  4. In the local view, set the fields and filter the records that you want.

  5. Run the view.

  6. Update the view results to update both the local table and the remote view.

  7. Close the local view and then the remote view to update the data on the remote server.

You can also combine local and remote data in a view by creating a new local view based on a local view and a remote view. You can have multiple levels of views between the top-level view and the local or remote base tables. When you use a multitiered view, the views on which the top-level view is based and any Visual FoxPro base tables used in the top-level or intermediate-level views appear in the Data Session window for the database. Remote tables do not appear in the Data Session window.

For example, the following code use the Northwind sample database and creates a local view that combines data from a local employee table and the remote orders table, you can use the following code:

OPEN DATABASE HOME(2) + "Northwind\Northwind"
CREATE SQL VIEW Local_Employee_View AS SELECT * FROM Employees
CREATE SQL VIEW Remote_Orders_View ;
   CONNECTION Remote_01 AS SELECT * FROM Orders
CREATE SQL VIEW Local_Employee_Remote_Orders_View ;
   AS SELECT * FROM Northwind!Local_Employee_View, ;
   Northwind!Remote_Orders_View ;
   WHERE Local_Employee_View.Emp_ID = Remote_Orders_View.Emp_ID

See Also

Tasks

How to: Create Local Views

Concepts

Accessing Remote Data Using Views

Other Resources

Creating Views
Working with Views (Visual FoxPro)