Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a web application in which i have users and while creating users i have locations and these location are in hierarchical pattern just like Country {contains} Cities,
Citites{contains} States,
States{contains} regions
same as according to my system i have
District ----------{contains 1...*}------------------------------------->tehsils
tehsils----------{contains 1...*}------------------------------------->UCS
UCS----------{contains 1...*}------------------------------------->Villages
I can assign a single user to one or many district , one or many Tehsils,one or many UCs,one or many Villages
so Top Level entity is District than Tehsil than UC than Villages i am doing this all in my application no worry :).
Now I have Question in my application and it is just like a quiz engine , I am assigning Question to each user through my system so each question also having Target value just like
Q#01: Number of schools Constructed (Target =12) {for District = "ABC}
Answer:Achived (10)

Now I want to ask you a db Design how much table i have to create and the relationship between them

I want to assign the target value based on location like one question can have a Target value based on District , or Tehsil, OR UC,OR Village but not all at the same time so user must answer the question relatively like answer achieved value for target value for District "ABC"
can i make a single table just like
Table(Question_ID,UserID,District,Tehsil,UC,Village,Target,Achieved)
it means it will insert the target vs achieved value based on location if district is selected then it will insert just like that)
Table(Question_ID,UserID,District,Tehsil,UC,Village,Target,Achieved)
VALUES(1,2,'ABC',NULL,NULL,NULL,10,1)
putting the NULLS for other location is it ok ?
I need assistance thanks in advance ... :)

What I have tried:

I have made a simple Table just like that
Table(Question_ID,UserID,District,Tehsil,UC,Village,Target,Achieved)
Posted
Updated 12-May-16 6:14am
v2
Comments
Mohibur Rashid 19-Feb-16 2:05am    
In "What I have tried" you copied and pasted last paragraph of your question description. In "What I have tried" you are suppose to write "What you actually have tried". What table structure you have designed or what you have wrote so far....
Malikdanish 19-Feb-16 2:21am    
I have updated that section now ..

1 solution

It is usually best to have one table per noun, but there are other ways as well.

GeoLevel
PK GeoLevelID
Name

Geography
PK GeographyID
ParentID <-- will be null for Districts
Name
GeoLevelID

Question
PK QuestionID
QuestionText
GeographyID
Target

User
PK UserID
UserName

User_Geography
PK UserID
PK GeographyID

Answer
PK QuestionID
PK UserID
Achieved
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900