Search code examples
sqldatabasesql-server-2012relationsql-server-2012-express

How to create tables to maintain users family relation?


I am working on a "family dictionary" project. I am creating tables in sql server. I am planning to give permission to user to create family, but I can't trust user. He/She can create multiple families.

What is the way to maintain unique family in sql server for several users ? for example:

id    fname    lname    sex    
1     Ashish   Jain      M
2     Neha     Jain      F
3     Sachin   Jain      M

How can I relate these all persons to a family? What process should I use to create a unique family in database?


Solution

  • You could have another table 'Family' with an id.

    And then from the first table, there would be a foreign key pointing to the family table.

    id    fname    lname    sex    familyid
    1     Ashish   Jain      M     1
    2     Neha     Jain      F     1
    3     Sachin   Jain      M     2