Results 1 to 4 of 4
  1. #1
    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 09:05.

  2. #2
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004

    Re: Tables without primary keys???

    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

  3. #3
    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).

  4. #4
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •