Jump to content

Proper assiging of id?


galvin

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.