# Db constraints to relation

**URL:** <https://forum.servoy.com/t/db-constraints-to-relation/7912>\
**Category:** Classic Servoy\
**Created:** [July 28, 2007, 6:30am UTC](https://forum.servoy.com/t/db-constraints-to-relation/7912 "2007-07-28T06:30:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![erdione](https://avatars.discourse-cdn.com/v4/letter/e/e9a140/32.png) [@erdione](https://forum.servoy.com/u/erdione)\
**Post date:** [July 28, 2007, 6:30am UTC](https://forum.servoy.com/t/db-constraints-to-relation/7912/1 "2007-07-28T06:30:41Z")

</div>

I made a test db with 3 tables

table\_a ( table\_a\_ id as integer and primary key)  
table\_b ( table\_b\_ id as integer and primary key, table\_a\_ id db constraint to table\_a _id)  
table\_c ( table\_c_ id as integer and primary key, table\_a\_ id db constraint to table\_a\_id)

in the relation form of servoy when i ask to create all my relations, it create the following relations:  
table\_a  
=\> fk\_table\_b\_table\_a  
=\> fk\_table\_c\_table\_a  
table\_b  
=\> pk\_table\_a

and nothing for table\_c

If i look in the servoy log, it said that it can’t create other pk\_table\_a relation because it already exist (for table b)

How can i recreate all my relation in servoy ( 300 constraints well defined in db engine)

Can you change the relation naming rule for example pk\_table\_b\_table\_b\_fields\_table\_a ?

Thanks

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [July 28, 2007, 10:26am UTC](https://forum.servoy.com/t/db-constraints-to-relation/7912/2 "2007-07-28T10:26:29Z")

</div>

Hi Fabrice,

> erdione:  
> How can i recreate all my relation in servoy ( 300 constraints well defined in db engine)

Yes you can (re)create all foreign-key constraints being used in the database in Servoy. Just open the Relations window. Select the correct connection name at the top and hit the Create button. After it is done you have all 300 foreign-key constraints in Servoy as well. keep in mind these constraints will be un-editable in Servoy.

> erdione:  
> Can you change the relation naming rule for example pk\_table\_b\_table\_b\_fields\_table\_a ?

You can’t change the naming rule but you can change the name after you selected all the properties though (except from the automatically created relations like discussed above)

Hope this helps.

---

<div class="post-metadata">

**Author:** ![erdione](https://avatars.discourse-cdn.com/v4/letter/e/e9a140/32.png) [@erdione](https://forum.servoy.com/u/erdione)\
**Post date:** [July 28, 2007, 2:58pm UTC](https://forum.servoy.com/t/db-constraints-to-relation/7912/3 "2007-07-28T14:58:28Z")

</div>

Thanks for your reply,

But all that you explain is what i’ve done in servoy (automatically create relation from the good connection pointing to db with constraints etc…) and the result is that there are missing relations because of duplicated name… (for exemple in table\_c)

For example if users table id is in many table because i want to know who created the record only one table (surely the first one) will get the relation

---

<div class="post-metadata">

**Author:** ![rgansevles](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rgansevles](https://forum.servoy.com/u/rgansevles)\
**Post date:** [July 31, 2007, 10:19am UTC](https://forum.servoy.com/t/db-constraints-to-relation/7912/4 "2007-07-31T10:19:54Z")

</div>

Fabrice,

You are correct, the current mechanism to generate relations from database foreign keys does not support a table with multiple FK relations referring to it.

We will change that in next versions of Servoy 3.1 and 3.5.

The new relation names will be :  
table\_a (unchanged)  
=\> fk\_table\_b\_table\_a  
=\> fk\_table\_c\_table\_a  
table\_b  
=\> table\_b\_to\_table\_a  
table\_c  
=\> table\_c\_to\_table\_a

Rob

---

<div class="post-metadata">

**Author:** ![erdione](https://avatars.discourse-cdn.com/v4/letter/e/e9a140/32.png) [@erdione](https://forum.servoy.com/u/erdione)\
**Post date:** [July 31, 2007, 10:54am UTC](https://forum.servoy.com/t/db-constraints-to-relation/7912/5 "2007-07-31T10:54:14Z")

</div>

Thanks for your reply

I think that The new relation should better be named like that  
fk\_field\_fktable\_pktable because we can have more than one constraint from one table to another table:  
for exemple see db diagram below and result of a sql query to discover constraint

table\_user  
=\> fk\_modifuserid\_table\_b\_table\_user  
=\> fk\_creatuserid\_table\_b\_table\_user  
=\> fk\_table\_c\_table\_user  
table\_b  
=\> pk\_modif\_user\_id\_table\_b\_table\_user  
=\> pk\_create\_user\_id\_table\_b\_table\_user  
table\_c  
=\> pk\_tab\_user\_id\_table\_c\_table\_user

“exec sp\_fkeys @pktable\_qualifier = null, @pktable\_owner = null, @pktable\_name = ‘table\_user’”

table\_user tab\_user\_id testfk dbo table\_b create\_user\_id FK\_create\_user\_id\_table\_b\_table\_a PK\_table\_a  
table\_user tab\_user\_id testfk dbo table\_b modif\_user\_id FK\_modif\_user\_id\_table\_b\_table\_a PK\_table\_a  
table\_user tab\_user\_id testfk dbo table\_c tab\_user\_id FK\_tab\_user\_id\_table\_c\_table\_user PK\_table\_a

 ![test_fk_servoy.JPG](https://canada1.discourse-cdn.com/flex010/uploads/servoy/original/2X/b/be9268e76453ee1ceee56a60abc9d1d44e49479f.jpeg)

---

<div class="post-metadata">

**Author:** ![erdione](https://avatars.discourse-cdn.com/v4/letter/e/e9a140/32.png) [@erdione](https://forum.servoy.com/u/erdione)\
**Post date:** [August 31, 2007, 2:18pm UTC](https://forum.servoy.com/t/db-constraints-to-relation/7912/6 "2007-08-31T14:18:02Z")

</div>

Does anybody have any date for the 3.5.1 Release ?

I need it to create my 2 or 3 hundreds relations in servoy (constraints are already created in my MSSQL server), it could be stupid to recreate it in Servoy

Thanks
