You can update multiple base tables from a view. When your view combines two or more tables, you set properties to ensure that only the many side of the view query is updatable.
Views are updated on a table-by-table basis. You must ensure that for each table accessed in a view, the key field set is a unique key for both the view result set and the base table.
To make a multitable view updatable
-
In the Query and View Designers, choose the Update Criteria tab, and then select the tables and field names you want to update.
-or-
-
Use the DBSETPROP( ) Function.
In most cases, the default values provided by Visual FoxPro prepare a multitable view to be updatable, even when you create the view programmatically. The following code example creates and explicitly sets properties to update a two-table view. You can use this example as a guide for customizing update property settings on a view.
Updating Multiple Tables in a View
Code | Comments |
---|---|
|
Create a view that accesses fields from two tables. |
|
Set the tables to be updated. |
|
Set update names. |
|
Set a single-field unique key for the Employee table. |
|
Set a two-field unique key for the Customer table. |
|
Set the updatable fields. Typically, key fields are not updatable. |
|
Activate the update functionality. |
|
Modify data in the view. |
|
Commit the changes by updating both the Employee and Customer base tables. |