SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Field referencing the primary key of its own table?

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    Australia
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Field referencing the primary key of its own table?

    I am introducing some year 10 students to databases. We are using Access2003 at the moment, and I am about to show them SQL (via Access).

    I have two questions which I will post seperately.

    I am trying to achieve the following:
    I have a database with basic information about a person (ID, first, last, DOB, mother, father).

    Currently we are playing with determining children by querying WHERE persons.mother = 'Lisa Jones'.
    I would like to change the 'mother' and 'father' fields into foreign keys ... on the same table. Is this possible? (I doubt it), so what is the correct way to do this?

  2. #2
    SitePoint Wizard
    Join Date
    Jul 2003
    Location
    Kent
    Posts
    1,908
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A person in a table can be the parent of another person in the same table. So yes you can use a foreign key that refers to the same table.

    Another example is a list of employees where many have a direct boss, who is also an employee in the same table.

    You can try this by opening the relationship window, then use Show Table to show the same one twice, then make a foreign key in the normal way.
    I think...

Bookmarks

Posting Permissions

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