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. #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    15,060
    Thanks
    165
    Thanked 2,250 Times in 2,237 Posts
    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?

  3. #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,687
    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
  •