How should I set up these tables in my relational database?

Posted on

Question :

I’m working on a project where a person can create a survey with custom questions and display the questions in whatever order they choose. They can break the questions into sections. The problem I’m having is that there are 2 or more groups of people. Each group can have the same question in different sections and/or in a different order. My tables right now are:

Group: key(gId), gName
Question: key(qId), qName
Section: key(sId), sName
QOrder: key(gId, qId), sId, qOrder

Is this okay or is there a better/more efficient way of doing this? Any help would be appreciated.

Answer :

Looks pretty good to me.

I’d also put unique index on qOrder, and all the *Name fields.

http://dev.mysql.com/doc/refman/4.1/en/constraint-primary-key.html
http://dev.mysql.com/doc/refman/5.6/en/create-index.html

Leave a Reply

Your email address will not be published. Required fields are marked *