If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Tables without primary keys???

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-21-04, 04:06
habibs habibs is offline
Registered User
 
Join Date: Jan 2004
Posts: 3
Question Tables without primary keys???

How to implement many-to-many relationship correctly?
I have Jobs and Empolyees tables. The rules are: One_Job_Can_Be_Assigned_To_Many_Employees
and
One_Employee_Can_Be_Assigned_To_Many_Jobs

I use JobsEmployees table that have 2 fields, jobID and EmployeeID, No primary key. As i know that is not good design to have tables without primary keys.
So, is there any other way to implement many-to-many relationship?

Any help is appreciated...

Last edited by habibs; 01-21-04 at 08:05.
Reply With Quote
  #2 (permalink)  
Old 01-21-04, 04:52
Bud Bud is offline
Registered User
 
Join Date: Dec 2003
Location: Dallas, TX
Posts: 995
Re: Tables without primary keys???

Quote:
Originally posted by habibs
How to implement many-to-many relationship correctly?
I have Jobs and Empolyees tables. The rules are: One_Job_Can_Be_Assigned_To_Many_Employees
and
One_Employee_Can_Be_Assigned_To_Many_Jobs

I use JobsEmployees table that have 2 fields, jobID and EmployeeID, No primary key. As i know that is not good design to have tables without primary keys.
So, is there any other way to implement many-to-many relationship?

Any help is appreciated...
Habibs,
As far as I have been taught and always implemented in my tables I use Primary Keys. You seem to have it down right. For a many-to-many relationship both of your main tables should have a PrimaryKey set. Then you create what some call a JoinTable or UnionTable and set both of your primary keys ONLY in that table...which then they are considered ForeignKeys. From that point on your data should work well, as I have a table just for that purpose myself. Have a nice one.
Bud
Reply With Quote
  #3 (permalink)  
Old 01-21-04, 07:29
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: Tables without primary keys???

You should add a primary key to the JobEmployees table on the pair of columns (jobID, EmployeeID).
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #4 (permalink)  
Old 01-21-04, 08:04
habibs habibs is offline
Registered User
 
Join Date: Jan 2004
Posts: 3
Hi Bud and Andrew, thanks for your replies. Just reviewed Northwind database that is in MSSqlServer and figured out the situation.
There are two tables , EmployeeTeritories and CustomerCustomerDemo showing the solution for this situation. In both tables, FK's defined as pair-PK's as andrewst suggested.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On