all groups > sql server new users > may 2005 >
You're in the

sql server new users

group:

Best practices: Relating many-to-many??


Re: Best practices: Relating many-to-many?? Hugo Kornelis
5/26/2005 12:00:00 AM
sql server new users:
[quoted text, click to view]

Hi Brian,

Yes, that is the correct approach.

CREATE TABLE SiteContacts
(SiteID int NOT NULL,
ContactID int NOT NULL,
PRIMARY KEY (SiteID, ContactID),
FOREIGN KEY (SiteID) REFERENCES Sites(SiteID),
FOREIGN KEY (ContactID) REFERENCES Contacts(ContactID)
)

You'll have to check and possibly correct the column names and datatypes
of course.

Best, Hugo
--

Best practices: Relating many-to-many?? Brian Mitchell
5/26/2005 7:36:25 AM
Hello, I am trying to figure out the best way to design a many-to-many
table relationship. For instance, I have a 'sites' table and a 'contacts'
table. The sites table contains the name and address for each of our remote
locations and the contacts table contains the name and phone number for the
local contact at each site. Now, my problem is that a site can have more
than one contact and a contact can have more that one site assigned. Is
there some way I can relate this back without having to duplicate data?



Thanks in advance!!

Brian Mitchell

Re: Best practices: Relating many-to-many?? Brian Mitchell
5/26/2005 7:52:55 AM
To get around the problem in the mean time, I just created a third table
that links them together. I don't know if this is the correct approach but
it seems to work for now.

[quoted text, click to view]

AddThis Social Bookmark Button