Currently i have requirement saying user from an UI creates there own forms which has types textbox,choicegroup etc.. Does anyone have a any idea on how to architect the database to store all data? If user want to link form1 to form2 etc.. how will these data links stored in database?

For example, parent1 has child1 & Child2, flow can be like this parent1->child1->child2.(In 1 single line how will parent child relationship need to be maintained in database tables)

  • 1
    Tables have id fields and children fields that point to this id. But your naming would be somewhat wrong here, since child2 would be a child of child1 not parent1. So basically since this is linear there are just forms following each other. So 'parent' would be 'head' or 'start' which is simply defined by the fact that the field 'parent_id' is null. So first form with id 1 has parent_id=null, first 'child' with id 2 has 'parent_id=1' and second 'child' has 'parent_id=2'. – thorsten müller Jun 3 '15 at 10:10

Parent-child relationships are usually implemented in databases by having a parent_id column. So, each child has a direct reference to its parent, and all the children of parent A can be found by performing a SELECT ... WHERE parent_id = A.

This has the disadvantage of not encoding the order of the children in any way, so if the children need to be ordered, then an additional order field is needed, usually of type real. Thus, inserting a child at a specific point along the list of children is done with new_child.order = (previous_child.order + next_child.order) / 2.

Other than that, it is unclear what you are asking. You appear to have unnecessarily complicated your question by including things about your user interface in the narrative. Your user interface considerations seem to be completely unrelated to the question of how to represent parent-child relationships in databases.

  • I am little confused in child ordering. can u please correct the below table : Parent : Equipment id(PK) | SchemeId | Parent_Equipment_Id | Componentid | component Order 1 | ABC | 0 | 11 | 1 2 | ABC | 1 | 22 | 1 3 | ABC | 1 | 33 | 2 4 | PQR | 1 | 55 | 4 5 | XYZ | 0 | 66 | 2 6 | XYZ | 2 | 77 | 1 7 | XYZ | 2 | 88 | 2 – Dheeraj Upadhyay Mar 13 at 2:47

This abstract of table can help u, which I am using in my project.

Parent : Equipment

Child : Component

Sub Child : Sub Component

Table 1 Columns
id(PK) | Parent_Equipment_Id | Componentid | component Order

Table 2 Columns

id(PK) | Parent_Component_Id | Sub_Component_id | sub_component_Order

There can be one to many relationship between your parent and child table, so it is very complicated to use single table

Also you need to create 3 Entities for Repository

  1. Abstract ParentEntity
  2. ChildEntity extends ParentEntity
  3. SubchildEntity extends ChildEntity

I hope it will help you to normalize your database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.