Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    13
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Lightbulb Multiple primary keys question

    I have a database with 7 tables. I have one ...main table which contains mostly the primary keys from the other tables. BUT, beeing a primary table, meaning that I need to add the data first in that primary table, then I need to read that data from other tables. My question is:
    Do I need to make all the keys in the main table as primary keys, then make those keys foreign keys in the other tables, or what would be the best aproach?

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    BUT, beeing a primary table, meaning that I need to add the data first in that primary table, then I need to read that data from other tables.
    Looks like your tables are not normalised and not getting any advantage of primary keys. Could you post your table schema?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by TAViX View Post
    I have a database with 7 tables. I have one ...main table which contains mostly the primary keys from the other tables. BUT, beeing a primary table, meaning that I need to add the data first in that primary table, then I need to read that data from other tables. My question is:
    Do I need to make all the keys in the main table as primary keys, then make those keys foreign keys in the other tables, or what would be the best aproach?
    this depend of your data model. Each table must refere to a single entity and each pair primary keys, foreign key must describe a relation between them.

    best regards


  •  

    Posting Permissions

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