Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2009
    Posts
    4

    which way to link two tables!!!!

    Hello,

    If you have two tables and you want to link them together using a foreign key. One table is only going to have a limited number of rows, for example department but the other table called employees could have 1000s of rows.

    If they where going to be linked, which would be the best way to link them and why? Or does it not make any difference?!!

    6 rows: department ( dep_id, dep_name, dep_address, ..... , emp_id*)

    1000s rows: employee ( emp_id, emp_name, emp_address, ..... )




    6 rows: department ( dep_id, dep_name, dep_address, ..... )

    1000s rows: employee ( emp_id, emp_name, emp_address, ..... , dep_id*)

    Thanks,

    newbie

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Do your departments contain one and only one employee?
    Do your employees belong to one and only one department?

    The answers to these questions should guide you.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Sep 2009
    Posts
    4
    OK there are six different departments and there are 1000 employees

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    yes - but what are the answers to the questions?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  5. #5
    Join Date
    Sep 2009
    Posts
    4
    Do your departments contain one and only one employee?

    Perhaps one department has one employee, and the rest of the departments could be divided between the other 999


    Do your employees belong to one and only one department?
    could be perhaps a small number of emplyees are soley employed by one department. The rest of the employees are divided by three or more departments.

    The answers to these questions should guide you.
    Still just as unclear..

  6. #6
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Ok - I'll put it another way. Suppose instead you have 1 department and 10 employees (to keep the numbers small).

    Regarding your first suggested design:
    For your one department you have a row. You enter an employee id for that row. Your department row now has an employee id entered in the emp_id column.
    So - you have assigned 1 employee to your department and 9 employees not assigned to any department. How do you assign these 9 to departments?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  7. #7
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    EDIT - Pat the Erudite phrased the questions better
    Last edited by pootle flump; 09-17-09 at 12:22.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  8. #8
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    To re-prhase Pootle's questions:

    1) How many employees can be in a department?

    3) How many departments can an employee be in?

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

Posting Permissions

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