AnsweredAssumed Answered

Copy an attribute value from one table to another, based on matching key attributes

Question asked by matt.walker@cartopac.com on Jun 5, 2012
Latest reply on Jun 27, 2012 by matt.walker@cartopac.com
I am trying to write a python script to copy an attribute value from one table to an attribute in another table, based on a primary key to foreign key match.  Basically, this is a workaround for relating an '_ATTACH' table to its parent table's record (the attachment record was created outside of Arc, so the 'REL_OBJECTID' attribute does not automatically get populated with the parent tables' record's 'OBJECTID', so I am trying to systematically repair this link).  I cannot figure out the syntax in using an updatecurser (or even if this is the way to do this!).

Let's say that I have a table, 'Table1' with a primary key, PK_GUID, field that is populated, and it has a system created attachment table, 'Table1_ATTACH' with a foreign key, FK_GUID, populated with the parent's primary key value (this is the link I can use in my where clause to link the records):

I need for the attribute Table1_ATTACH.REL_OBJECTID to be populated with Table1.OBJECTID

I attempted to write a script to do this, mimicking some bad code I found in my google search:

#define the parent table Table2 = r"database connections\connection to db\db.DBO.Table1__ATTACH"  #create a cursor on the child table's record that is linked to the parent table's record on the non-ESRI keys Rows = arcpy.UpdateCursor("db.DBO.Table1__ATTACH", "select * from db.DBO.Table1 where db.DBO.Table1.PK_GUID = db.DBO.Table1_ATTACH.FK_GUID", "", "REL_OBJECTID") for row in rows:  row.REL_OBJECTID = T2.OBJECTID 


Am I anywhere near close on this one?

Outcomes