Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Relating unrelated tables using a thrid table

Author  Topic 

krisleech
Starting Member

1 Post

Posted - 2003-06-06 : 17:57:45
hi all,

Can you tell me if this is right .

Q). I have two tables one called PersonTBL and one called GroupsTBL, the idea being each Person can be in many Groups. So do i need a third table to create a relationship between the two Tables?
ie. a third table called say People_IN_Groups that is just two fields eg. PersonID and GroupID?
Each time you wish to relate a person to a group you add a record to the People_IN_Groups table with the PersonID of the person and the GroupID of the Group they are related to.

Many thanks Kris.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-06-06 : 18:02:20
Yes that is one way to do it. That is the way that we manage a grouping of users/people here. Don't forget to add foreign keys!

Tara
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2003-06-06 : 18:13:25
You need this type of structure to reflect a many to many relationship.

The table in the middle is called a conjoint table, linking table, join table, association table, junction table, ....
I call it a conjoint.

Keep a consistent naming convention for these tables and the fields in them.
People_Groups_Memberships?
(Plural table names? yuk!).


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-06-06 : 18:18:04
We've got a conjoint table called Company_Company_Group, which is a grouping of companies. I just hate the name.


Tara
Go to Top of Page

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2003-06-06 : 18:50:55
we typically names these with an _xref extension.

Maybe your table would be Person_Group_XREF or something like that. Keeps it easy to understand the function of the table.


-ec

Go to Top of Page
   

- Advertisement -