create foreign key relationships with script


I have a few reverse engineered databases, which do not contain a single relationship. A few are oracle db’s and others are ms sql db’s.

I see the names of the attributes at least make sense as to which entities are related. I’ve dabbled a bit, but just cannot get the hang of creating foreign keys with a script.


Table1 -> Primary Key Att = Table1_ID
Table2 -> Contains an Att called Table1_ID already

I want to just create a relationship between these two with the Table1 being the parent and Table2 being the child.

Then I can easily map the database for future use.

Thank you in advance for the assistance.

Additional Info:

When running this line of code…
var lRel = Model.CreateNewObject(2004);

I get the following error…
Source: CS3 - Internal error
Description: Access violation at address 00E5BF57 in module ‘TDM.exe’. Read of address 00000000
Row: 8
Column: 3

Rudi Louw

Message was edited by: RudiL

Hi Rudi,

what version of TDM do you have? The latest version 4.2 contains automatic foreign keys mapping. See

Please try the latest version and just draw relationship from Table1 to Table2.



Hi Rudi,

if you need/wish to use scripting, either try the Infer Relationship macro (menu Macros | All | Infer Relationship) or see the source code of the macro.



Hi Vaclac

I’m running version, which I see when I draw the relationships manually, it’s works fine (the case sensitivity messes with this feature though).

But I had to do that with 44 Entities, checking the primary key of each one, to see if it’s contained in any of the other entities.

The Infer Method worked as well, except for the fact that it creates an identifying relationship (I need a non-identifying one) and also re-creates the attribute for some reason after giving me the following error, then jumping to that code of the macro:

Source: Microsoft JScript runtime error
Script: InferRelationship
Description: Object required
Row: 121
Column: 18

So now the entity contains duplicate attributes.

But I looking at the infer-relationship code, I can already see where I’m going wrong.

Thank you for your response

Hi Rudi,

thank you for the info. We will do additional tests of the Infer Relationship macro.
In case you need our assistance, please feel free to write us again.