Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Uncertain on What to Use as Foreign Key of a Table

Uncertain on What to Use as Foreign Key of a Table

Scheduled Pinned Locked Moved Database
databasecareerdesignxmlhelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ASPnoob
    wrote on last edited by
    #1

    Hi all, I am trying to design a database to hold data for a job portal. Basically I have a database called SiteUsers which contains five tables (UsersTable, JobSeekersTable, ResumesTable, EmployersTable, and JobsTable). The following are the table schema for UsersTable, ResumesTable, and JobsTable. The UsersTable has a Primary Key (PK) of UserID and a Foreign Key (FK) of Username. The ResumesTable has a PK of ResumeID and the JobsTable has a PK of JobID. The JobSeekersTable has a PK of Username. The EmployersTable has a PK of Username. The question I have is should the JobSeekersTable FK also be Username, or ResumeID, or a composite of Username and ResumeID. I think that the FK should be Username because it's unique but because it's not the primary key of the JobsTable I am uncertain. Also I did not want to use ResumeID as the FK in the JobSeekersTable because although it will be unique a job seeker can have more than one resume. Whether you agree or disagree with my assumption that Username should be the PK and FK in the JobSeekersTable, please elaborate your answer . Thanks in advance for your help.

    P L 2 Replies Last reply
    0
    • A ASPnoob

      Hi all, I am trying to design a database to hold data for a job portal. Basically I have a database called SiteUsers which contains five tables (UsersTable, JobSeekersTable, ResumesTable, EmployersTable, and JobsTable). The following are the table schema for UsersTable, ResumesTable, and JobsTable. The UsersTable has a Primary Key (PK) of UserID and a Foreign Key (FK) of Username. The ResumesTable has a PK of ResumeID and the JobsTable has a PK of JobID. The JobSeekersTable has a PK of Username. The EmployersTable has a PK of Username. The question I have is should the JobSeekersTable FK also be Username, or ResumeID, or a composite of Username and ResumeID. I think that the FK should be Username because it's unique but because it's not the primary key of the JobsTable I am uncertain. Also I did not want to use ResumeID as the FK in the JobSeekersTable because although it will be unique a job seeker can have more than one resume. Whether you agree or disagree with my assumption that Username should be the PK and FK in the JobSeekersTable, please elaborate your answer . Thanks in advance for your help.

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2
      1. You don't actually define a foreign key on a table 1) You may want to define a unique index on UsersTable, but don't use it as a foreign key 2) The other tables should be related to UsersTable on UserID, not on Username
      1 Reply Last reply
      0
      • A ASPnoob

        Hi all, I am trying to design a database to hold data for a job portal. Basically I have a database called SiteUsers which contains five tables (UsersTable, JobSeekersTable, ResumesTable, EmployersTable, and JobsTable). The following are the table schema for UsersTable, ResumesTable, and JobsTable. The UsersTable has a Primary Key (PK) of UserID and a Foreign Key (FK) of Username. The ResumesTable has a PK of ResumeID and the JobsTable has a PK of JobID. The JobSeekersTable has a PK of Username. The EmployersTable has a PK of Username. The question I have is should the JobSeekersTable FK also be Username, or ResumeID, or a composite of Username and ResumeID. I think that the FK should be Username because it's unique but because it's not the primary key of the JobsTable I am uncertain. Also I did not want to use ResumeID as the FK in the JobSeekersTable because although it will be unique a job seeker can have more than one resume. Whether you agree or disagree with my assumption that Username should be the PK and FK in the JobSeekersTable, please elaborate your answer . Thanks in advance for your help.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        A foreign key is a primary key from another table. The "username" in the Users table (calling it userstable is redundant, all those things are tables and not chairs with little chance of confusing those) is not a foreign key - but it might be candidate-primary key. Also, the artificial autonumber may be unique, but it does not mean that one can assign it blindly to be the primary key without asking oneself what the user will be using to uniquely identify a record. You should look into normalization.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        A 1 Reply Last reply
        0
        • L Lost User

          A foreign key is a primary key from another table. The "username" in the Users table (calling it userstable is redundant, all those things are tables and not chairs with little chance of confusing those) is not a foreign key - but it might be candidate-primary key. Also, the artificial autonumber may be unique, but it does not mean that one can assign it blindly to be the primary key without asking oneself what the user will be using to uniquely identify a record. You should look into normalization.

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

          A Offline
          A Offline
          ASPnoob
          wrote on last edited by
          #4

          Hi, thanks for responding. You said "calling it userstable is redundant", that was a typo.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups