Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Adding records to views, parent tables
Message
From
13/10/1999 10:59:47
 
 
To
13/10/1999 10:39:36
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00275810
Message ID:
00275833
Views:
26
Hi Mary-Ann,

You treat views like if they were tables. You insert the parent record first, the insert all the childs in the corresponding views. You start with the parent first, because you may have a relation integrity rule that prohibit inserting a child without a parent.

To be sure that all records will be saved, you can include all the TableUpdate() inside a BEGIN TRANSACTION...END TRANSACTION loop.

Example:
INSERT INTO Parent VALUES (...)
INSERT INTO Child1 VALUES (...)
...
INSERT INTO Child2 VALUES (...)
...
BEGIN TRANSACTION

IF TableUpdate(.T., .F., "Parent")
   IF TableUpdate(.T., .F., "Child1")
      IF TableUpdate(.T., .F., "Child2")
         END TRANSACTION
      ELSE
         ROLLBACK
      ENDIF
   ELSE
      ROLLBACK
   ENDIF
ELSE
   ROLLBACK
ENDIF
Of course, you may want to display a message if the transaction fail.

HTH
>Really missing something. When you have a database with say, six tables that are all related, I figured the best way to work with the information is to create views of each. Having trouble when you want to add a record to the parent table (which then also needs to add a record to all the child tables). I am Inserting Into the view that comes from the primary/parent table. Do I also need to insert to all the child views? Bottom line, what is the best way to add a record to the Parent table and all the related child tables?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform