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
 General SQL Server Forums
 Database Design and Application Architecture
 Sql2005 Many To Many

Author  Topic 

bpasutti
Starting Member

2 Posts

Posted - 2009-02-02 : 13:08:13
Hi,

I'm very new to SQL. I am currently working on an application for a small business. My MCDBA quit the project and left me high and dry

Here is my issue. I have 3 tables (Company, Jobs, Contacts)
The jobs table needs to track many companies and many contacts.
Companies can have many contacts.
Contacts can have only 1 company.

Can I do this?
[TableCompany(id)] [TableJobs(id)] [Contacts(id)] Then create a reference table:
[TableCntsJobsCmpy(jobsid-contactsid-companyid)] with all 3pk ids?

I have no idea

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-02 : 13:11:19
isnt it enough to add companyid and contactid to jobs table? will there be contact without job and also company without any job?
Go to Top of Page

bpasutti
Starting Member

2 Posts

Posted - 2009-02-02 : 14:22:03
Hi visakh16 ,

Yes companies and contacts may exist without having a job attached to them.

So If I enter a company and contact .. they may not be used in any jobs.

So will your solution work?
Thanks,
Blaine
quote:
Originally posted by visakh16

isnt it enough to add companyid and contactid to jobs table? will there be contact without job and also company without any job?

Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-02 : 19:34:54
quote:
Originally posted by bpasutti

Hi,

I'm very new to SQL. I am currently working on an application for a small business. My MCDBA quit the project and left me high and dry

Here is my issue. I have 3 tables (Company, Jobs, Contacts)
The jobs table needs to track many companies and many contacts.
Companies can have many contacts.
Contacts can have only 1 company.

Can I do this?
[TableCompany(id)] [TableJobs(id)] [Contacts(id)] Then create a reference table:
[TableCntsJobsCmpy(jobsid-contactsid-companyid)] with all 3pk ids?

I have no idea





I don't see any Many-Many relationships between tables so why you need reference table. Why don't you link tables with appropriate fk?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-03 : 09:20:00
quote:
Originally posted by bpasutti

Hi visakh16 ,

Yes companies and contacts may exist without having a job attached to them.

So If I enter a company and contact .. they may not be used in any jobs.

So will your solution work?
Thanks,
Blaine
quote:
Originally posted by visakh16

isnt it enough to add companyid and contactid to jobs table? will there be contact without job and also company without any job?




yup..no problem with that. and if they've a job, they will have a record in job table
Go to Top of Page
   

- Advertisement -