# How to create a relation between two tables via script - reloaded?

**URL:** <https://forums.toadworld.com/t/how-to-create-a-relation-between-two-tables-via-script-reloaded/2316>\
**Category:** Toad Data Modeler\
**Created:** [August 2, 2010, 11:28am UTC](https://forums.toadworld.com/t/how-to-create-a-relation-between-two-tables-via-script-reloaded/2316 "2010-08-02T11:28:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndreasL](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@AndreasL](https://forums.toadworld.com/u/AndreasL)\
**Post date:** [August 2, 2010, 11:28am UTC](https://forums.toadworld.com/t/how-to-create-a-relation-between-two-tables-via-script-reloaded/2316/1 "2010-08-02T11:28:02Z")

</div>

Some questions to the result of running the following script:  
Relation = Model.AddLinkObject(2004, TenantEntity, Entity);  
Relation.Name = RelationName;  
Relation.Caption = RelationName;  
Relation.Identifying = false;  
Relation.MandatoryParent = false;  
Attribute = Relation.ForeignKeys.GetObject(0).AttrChild;  
Attribute.Name = AttributeName;  
Attribute.Caption = AttributeName;  
Attribute.Ordinal = 2;  
Attribute.NotNull = false;  
Pk = Entity.Keys.GetObjectByName(Prefix+’\_PK’);  
if (Pk == null) {  
System.ShowMessageDialog(1000,‘AdaptEntitiesDialog’,‘Could not find PK ‘+Prefix+’\_PK’,3,4);  
}  
else {  
// Remove from Pk.KeyItems  
}

1. How to prevent the new attribute being added to the primary key?

2. Or as workaround: How to remove an item from the KeyItems list?

3.Why is the new FK attribute always at the bottom and Attribute.Ordinal=2 ignored? How to move it up to the second position inthe script?

Thanx a lot.  
Andreas

---

<div class="post-metadata">

**Author:** ![AndreasL](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@AndreasL](https://forums.toadworld.com/u/AndreasL)\
**Post date:** [August 3, 2010, 1:18am UTC](https://forums.toadworld.com/t/how-to-create-a-relation-between-two-tables-via-script-reloaded/2316/2 "2010-08-03T01:18:34Z")

</div>

Please help…  
Are all people on holidays out there?

Andreas

---

<div class="post-metadata">

**Author:** ![vladka](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/vladka/32/41_2.png) [@vladka](https://forums.toadworld.com/u/vladka)\
**Post date:** [August 3, 2010, 3:09am UTC](https://forums.toadworld.com/t/how-to-create-a-relation-between-two-tables-via-script-reloaded/2316/3 "2010-08-03T03:09:56Z")

</div>

Hi Andreas,

See the reply at:  
[http://modeling.inside.quest.com/thread.jspa?messageID=105470&tstart=0#105470](http://modeling.inside.quest.com/thread.jspa?messageID=105470&tstart=0#105470)

Thanks for your patience.

Regards,

Vladka + TDM Team
