Partager via


How to: Create Local Views

Local views use Visual FoxPro SQL syntax to select information from tables or views that are stored locally on your computer. You can create local views in the following ways:

  • Using the Local View Wizard.

    A wizard is the easiest way to start creating a view. You can select fields from tables and views and filter and sort the records in your view. For more information, see Creating Local Views Using a Wizard.

  • Using the View Designer.

    The View Designer makes it possible to select fields from tables or views, specify criteria for retrieving data and join conditions, and filter, sort, and group records to create views or customize existing views. For more information, see Creating Local Views Using the View Designer.

  • Creating views programmatically.

    The CREATE SQL VIEW command makes it possible for you to use SQL SELECT statements so you can create views programmatically. For more information, see Creating Local Views Programmatically.

Regardless of the method you use, the basic process for creating a view is generally the same. For more information, see View Creation.

Note

When you create or use a view from the Project Manager, the Project Manager opens the database automatically. However, if you subsequently use a view outside the project, you must open the database or make sure the database is in scope before you can use the view.

Creating Local Views Using a Wizard

You can create local views easily using a wizard. The wizard helps you select tables or views and creates a query based on your answers to a series of questions.

Note

The tables or views you want to use must be part of a project or database before you can use the Local View Wizard to create a view. For more information, see Working with Projects and Developing Databases.

To start the Local View Wizard

  1. Perform one of the following:

    • Open a database in the Database Designer.

      -OR-

    • Open the project for your application in the Project Manager, and click a database or table.

  2. On the Tools menu, point to Wizards, and click All Wizards.

  3. In the Wizard Selection dialog box, click Local View Wizard, and then OK.

  4. Follow the instructions on the wizard screens.

For more information, see Local View Wizard.

Creating Local Views Using the View Designer

You can use the View Designer to create views and specify additional options or customize existing views.

Note

The tables or views you want to use must be part of a project or database before you can use View Designer to create a view. For more information, see Working with Projects and Developing Databases.

To start the View Designer

  1. Perform one of the following:

    • Open a database in the Database Designer.

      -OR-

    • Open the project for your application in the Project Manager, and click a database.

  2. On the File menu, click New.

  3. In the New dialog box, click View, and then New File.

    The Add Table or View dialog box appears.

  4. In the Select area of the Add Table or View dialog box, click Tables to display available tables or Views to display available views.

  5. Click the tables or views you want to use, and then Add.

    Tip

    When you add more than one table or view to your view, the Join Condition dialog box appears. You can modify the scope of resulting records by specifying a join condition for each additional table or view.

    Tip

    When you select the same table or view more than once, Visual FoxPro uses an automatically generated alias for the table or view. However, you can specify an alias for each table or view that you select by typing it in the Alias box in the Add Table or View dialog box.

    The tables or views you select appear in the View Designer and Database Designer.

  6. When you are finished, click Close.

For more information specifying join conditions, see How to: Control Record Selection with Joins, Join Conditions for Tables, Queries, and Views, and Join Condition Dialog Box.

After selecting tables or views, you need to select the fields that contain the data you want to retrieve the data for your view. For more information, see How to: Select Fields for Views.

Creating Local Views Programmatically

You can create local views programmatically by opening the View Designer or specifying a SQL SELECT statement.

To create a local view programmatically

  1. Open the database or project containing the tables or views you want to select.

  2. Choose one of the following:

    • To select tables or views and open the View Designer, use the CREATE SQL VIEW command with only the name of the view you want to create.

    -OR-

    • To create a local view without opening the View Designer, use the CREATE SQL VIEW command and the AS clause to specify SQL SELECT statements.

      Note

      To match related records between the tables, you must specify a join condition in the FROM or WHERE clause of the SQL statement used in the CREATE SQL VIEW command. If persistent relationships between the tables exist, they are automatically used as join conditions.

    The tables or views you select appear in the View Designer and Database Designer. You might need to close and reopen the designers to update them.

For more information, see CREATE SQL VIEW Command.

See Also

Tasks

How to: Add Tables to Views

Concepts

View Creation

Accessing Remote Data Using Views

Other Resources

Creating Views

Working with Views (Visual FoxPro)