General information
Category:
Databases,Tables, Views, Indexing and SQL syntax
Gary,
I do not know whether I can explain it clearer, but below is how it works for me.
Let us suppose there are two free tables sta_mstr and sta_prcs having indexed fields sta_mstr.station and sta_prcs.key1, both are primary keys. Table sta_prcs has foreign key station.
Now I want to update fields sta_mstr.address and sta_prcs.econ for station="3333" using single updateable view.
*----------------------
clear
close table all
close data all
create data tempdata
add table sta_mstr
add table sta_prcs
create view statview as;
select ;
sta_mstr.station , ;
sta_mstr.address, ;
sta_prcs.key1,;
sta_prcs.econ;
from sta_mstr, sta_prcs;
where sta_prcs.station+rec_type=sta_mstr.station and;
rec_type="15"
?dbSetprop("statview.station","FIELD", "KeyField" , .T.)
?dbSetprop("statview.key1","FIELD", "KeyField" , .T.)
?dbSetprop("statview.address","FIELD", "Updatable", .T.)
?dbSetprop("statview.econ","FIELD", "Updatable", .T.)
?dbSetprop("statview","VIEW", "SendUpdates", .T.)
sele 0
use statview
loca for station="3333"
repl address with "New Address", econ with 111.11
on error tablerevert()
?tableupdate()
close table all
remove table sta_mstr
remove table sta_prcs
close data all
erase tempdata.db*
on error
*----------------------------
Hope it'l help.
>I encourage anyone who beleives they can explain this concept clearer than the documentation to please respond. I created two simple tables and a inner join view to experiment with. The documentation example shows issuing replace statements referencing the fields qualified by table names not the view names. If I don't use any reference, I can update the entire view with a replace all. When I qualify the fields with the table the way the example shows, random records are updated, usually only the last one. What specifically is meant by "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." I am referencing the help topic and example from "Updating Multiple Tables in a View" in VFP 7.
>
>Thanks,
>
>Gary Pike
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only