Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Updating new parent key into child table
Message
From
21/12/2000 08:18:59
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00455723
Message ID:
00455823
Views:
25
This code should do the trick:
SELECT Exec

SCAN
   SELECT Corp
   REPLACE ALL cCorp_Id WITH Exec.cCorp_Id FOR CorpId = Exec.CorpId
ENDSCAN
That being said, I don't recommend using Sys(2015) as a primary key generator. Sys(2015) doesn't give you a garantee of uniqueness, even more so in a networked environment. Also, I don't like character field as a primary key because you have to make sure in your comparison that SET EXACT is ON or that SET ANSI is ON or that you use "==". You also need to take into consideration blanks and upper/lowercase. It is much easier to work with integer field, IMHO.

HTH
>I have a corporation parent table with an executive child table. These are older tables that use a numeric 'corpid' to link the two tables. I want to update the primary key to use sys(2015). I added a new field in the parent table called ccorp_id with the new style key, and now I want to update all the child records with that new key.
>
>For example: Parent Corp record has a corpid=1 and all the child record reference that corpid of 1 in the child table. I want to update the ccorp_id field in the child table to match the ccorp_id in the parent table.
>
>I have tried to put together an update SQL that sets corp.ccorp_id=exec.ccorp_id (new key) where corp.corpid=exec.corpid (old key), but I just can't seem to get the syntax correct.
>
>Can anyone help me with this?
Previous
Reply
Map
View

Click here to load this message in the networking platform