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. General Programming
  3. C / C++ / MFC
  4. database schema design question

database schema design question

Scheduled Pinned Locked Moved C / C++ / MFC
databasequestiondesignxmlhelp
2 Posts 2 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.
  • P Offline
    P Offline
    ppp001
    wrote on last edited by
    #1

    Hi, I have two objects, both point to each other in OO. e.g. Class Father { private int id; //id of father private Son son; } Class Son { private int id; //id of Son private Father father; } so I need to have two tables in database as follow, Table Father : (id, SonId) Table Son : (id, FatherId) The problem is, should I eliminate the one of the reference in one of the table, e.g. Table Father : (id) Table Son : (id, FatherId) so I just have the fatherID in the son table. But if I remove the sonID from the father table, I need to join the two tables when I retrieve fathers from the father table. So what are the pros and cons of the two schema design ? Thanks

    M 1 Reply Last reply
    0
    • P ppp001

      Hi, I have two objects, both point to each other in OO. e.g. Class Father { private int id; //id of father private Son son; } Class Son { private int id; //id of Son private Father father; } so I need to have two tables in database as follow, Table Father : (id, SonId) Table Son : (id, FatherId) The problem is, should I eliminate the one of the reference in one of the table, e.g. Table Father : (id) Table Son : (id, FatherId) so I just have the fatherID in the son table. But if I remove the sonID from the father table, I need to join the two tables when I retrieve fathers from the father table. So what are the pros and cons of the two schema design ? Thanks

      M Offline
      M Offline
      Mayur Mahajan
      wrote on last edited by
      #2

      If you keep the references in both the tables, you can improve the efficiency by eliminating joins. You can find all 'children' of a 'father' and vice versa by a simple query on a single table. The down side however is an additional overhead in maintaining the redundant data consistently. You need to make sure to update the respective fields whenever any child is to be deleted or the other way. Just see what is preferable for your application, efficiency or simplicity... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

      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