galvin Posted March 23, 2011 Share Posted March 23, 2011 Newbie here just looking for a simple explanation if there is one (I realize there might not be one). Say I have an application where there will be tests, questions, and answers. From what I read about normalization, it seems like the proper way to do it would be to have THREE tables.. TESTS (with fields like testid, testname, etc) QUESTIONS (with fields like testid, questionid, question, etc) ANSWERS (with fields like testid, questionid, answerid, answer, etc) What I don't get is this... Since every question will have a corresponding answer, why not have TWO tables like this... TESTS (with fields like testid, testname, etc) QUESTIONSANDANSWERS (with fields like testid, questionid, question, answerid, answer, etc) It would seem that it would be easier to have all the Q & A stuff in ONE table so that my queries only have to query ONE table, but everything I read seems to indicate that this would be "normalized" by having the questions and answers in TWO separate tables. It seems backwards to me so if there is anyone that can explain the theory behind this "normalization" stuff like I'm a 5 year old, please enlighten me. Or is it possible that my example should be done the 2nd way? haha, I doubt it, but have to ask. I just want to make sure I do things the proper way before I delve into this project. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/231454-question-on-normalization-basics/ Share on other sites More sharing options...
optikalefx Posted March 24, 2011 Share Posted March 24, 2011 So the reason you want them all as separate tables is because what if you have multiple answers to 1 question. Now what? Now you have a 1 to many relationship that you need the questions and answers table for. Quote Link to comment https://forums.phpfreaks.com/topic/231454-question-on-normalization-basics/#findComment-1191557 Share on other sites More sharing options...
galvin Posted March 25, 2011 Author Share Posted March 25, 2011 Ok, understood, but what if it was a 100% chance that you would always have 1 answer to 1 question? Would it then make sense to do it in one larger table, or is it still better practice to do it with separate tables? Quote Link to comment https://forums.phpfreaks.com/topic/231454-question-on-normalization-basics/#findComment-1191998 Share on other sites More sharing options...
optikalefx Posted March 25, 2011 Share Posted March 25, 2011 if you were 100% that it will never be a many to 1 relationship than an 'answer' is just a property of a question. Therefore it can just be a field on the question table. But you also have to ask, will there ever be information about an answer that isn't directly about the question? Like, how long it took to answer that question, what order the answer appeared in, etc.. That all could still be on the question table, but you wanna make sure that an answer is just 1 piece of info about a question and it isn't an entity of its own. Quote Link to comment https://forums.phpfreaks.com/topic/231454-question-on-normalization-basics/#findComment-1192045 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.