Results 1 to 4 of 4
  1. #1
    threepwoodjr is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2011
    Posts
    5

    Foreign keys in a consolidated table

    I have a database that tracks users, tickets, and inventory. I'm trying to consolidate tables. For example, currently I have multiple comment tables, tblUserComments, tblTicketComments, etc. I want to have one table for comments. However, I'm having a problem understanding how to deal with foreign keys. This is what I have:

    tblUser
    --tblUser_ID (pk, autonumber)
    --tblUser_LastName
    --tblUser_FirstName
    --tblUser_Office
    --tblUser_Phone

    tblTicket
    --tblTicket_ID (pk, autonumber)
    --tblTicket_Title
    --tblTicket_Description
    --tblTicket_Status
    --tblTicket_Opened
    --tblTicket_Closed

    tblComment
    --tblComment_ID (pk, autonumber)


    --tblComment_ObjectID (fk, ticketID, userID, etc)
    --tblComment_Comment
    --tblComment_DateTime

    The problem I'm having is when I want to display all the comments for a particular user or ticket, how will it distinguish between users and tickets. In the foreign key field in the comments table, it will have 1. This could be user 1 or a ticket 1.

    I thought about adding an additional field like tblComment_SourceTable but that's a lot of redundant data. I thought about adding a T or a U to the primary key but I don't know how to do that and I'm reading thats bad to add descriptive info to a primary key.

    I appreciate your help. My knowledge with Access is basic and self-taught. I usually end up rigging it to work somehow and it's not the best way to do it.

    -Mike

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You were on the right track. Since you have comments referencing two different subjects (tables) you have no choice (IMO) but to add an additional field to the table that describes to what the comment refers.

  3. #3
    threepwoodjr is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2011
    Posts
    5
    Thanks for your help. I was stuck on this and not sure of the best way to move forward. This sets me in the right direction.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Glad I could help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Multiple Foreign Help
    By Dalagrath in forum Access
    Replies: 2
    Last Post: 11-01-2010, 10:25 AM
  2. Multiple foreign key in table
    By pmstirling in forum Database Design
    Replies: 10
    Last Post: 02-23-2010, 04:00 PM
  3. Getting a foreign key set
    By bkelly in forum Access
    Replies: 5
    Last Post: 08-18-2009, 09:22 PM
  4. Primary/foreign keys + relationships
    By tripptofer in forum Database Design
    Replies: 0
    Last Post: 08-12-2009, 07:44 AM
  5. Foreign Data
    By bmiller in forum Queries
    Replies: 0
    Last Post: 03-21-2006, 01:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums