galvin Posted November 3, 2011 Share Posted November 3, 2011 I have a table called "answers" that is going to store a ton of answers to questions, that belong to various quizzes. Among others, I have two columns (totally off subject question...are these called "columns" or "fields" or are both acceptable??) in mysql called .. -answerid -quizid Rather than assigning a universally unique answerid to each answer, I am currently assigning answerids starting at 1 FOR EACH QUIZ, since in my mind, the quizid field in conjunction with the answerid field makes that particular answer unique (should uniqueness be necessary at some point later in this project). For example, if I my first 3 quizzes each have 3 answers, it would look like this... answerid-quizid 1-1 2-1 3-1 1-2 2-2 3-2 1-3 2-3 3-3 Instead of using universally unique answerids like this... 1-1 2-1 3-1 4-2 5-2 6-2 7-3 8-3 9-3 Now, I don't really have a reason for needing to do the former, so before I get much further with this project, I wanted to ask if doing the former is OK, or is the latter method better for some reason? I guess the ultimate question is: Should every item in a mysql table have a UNIQUE id? If so, why? Quote Link to comment Share on other sites More sharing options...
joel24 Posted November 3, 2011 Share Posted November 3, 2011 you're trying to use a composite primary key which is fine and unique. i.e. your primary key would be (quizid, answerid) google it or have a quick read here as for columns or fields, I hear both terms used frequently - i'm sure someone else will have some input into this question. Quote Link to comment Share on other sites More sharing options...
fenway Posted November 3, 2011 Share Posted November 3, 2011 It's often quite beneficial to have a unique id for each record in each table. Quote Link to comment 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.