Results 1 to 14 of 14

Thread: database design question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405

    database design question

    I am having difficulty designing a database, it seems straightforward enough, but i'm having issues, any help would be appreciated.

    The basic concepts are:
    company
    promotion
    quiz
    question
    customer

    every company has more than one promotion
    every promotion can only have 0 or one quiz
    every quiz can have many questions.

    The problem i have is how to relate customers (and their answers) to the quiz/questions.

    A customer may only play a promotions quiz once.
    (the start and end time of when the customer layed the quiz also need to be recorded)

    many customers can play a promotions quiz

  2. #2
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: database design question

    If I'm understanding you correctly you want a 'Customer_Answer' table which would act as a linking entity between customer and question. The Customer_Answer table should a record containing a question number, the customer number and the answer they gave. You already know for each question what quiz it belongs to so there's no need to link to that.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405

    Re: database design question

    Thanks for the reply funkydexter.

    I understand how your solution would work, but how/where would i log the start and end times for the customer. (basically i want to be able to say, this customer took 10 minutes to complete the quiz).

    I guess it wouldn't be correct to log this in the customeranswer table, as that is per answer, rather than the whole quiz.

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: database design question

    I think you might want a little different setup. I would use a table between customer and quiz. That would allow you to record a start and stop time for the quiz and create a unquie key constraint on the table using the quiz PK and the customer PK. That would allow you to prevent a customer from taking a quiz more then once.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  5. #5
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: database design question

    You need a Customer_Quiz table that has the Customer_ID and Quiz_ID as a combined PK (this will prevent a customer from taking a quiz twice.)
    In this table you can store the start and end times for the quiz.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  6. #6
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: database design question

    I think you might want a little different setup. I would use a table between customer and quiz. That would allow you to record a start and stop time for the quiz and create a unquie key constraint on the table using the quiz PK and the customer PK. That would allow you to prevent a customer from taking a quiz more then once. Then a table that would hold the question and answers for that quiz customer combination.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  7. #7
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: database design question

    Gary
    great minds think alike (and I guess us idiots do too)
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  8. #8
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: database design question

    Yep, as others have said, if you're going to have start and end times you're going to have to connect it to quiz as well with a Customer_Quiz table. I think you'll actually want this in addition to Customer_Answer table because you're still going to want to store the answers each customer gave.

  9. #9
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: database design question

    Hmmm, ER(Entity-Relationship) Diagrams should show the idea of the peeps well sagey.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405

    Re: database design question

    thanks to all for your help so far.
    I have attached a png of an er diagram from sql server, is this the basics of what you were describing?
    Attached Images Attached Images  

  11. #11
    Fanatic Member BillBoeBaggins's Avatar
    Join Date
    Jan 2003
    Location
    in your database, dropping your tables.
    Posts
    628

    Re: database design question

    No need to link the tbl_CustomerAnswer to tbl Customer, just make the answer table relate to the question table, which in turn relates to the test table, and through the CustomerTest table you can establish, which test, which question and what the answer is.

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405

    Re: database design question

    Cheers for the reply bilbo.

    Not sure if what you are suggesting is correct. if there is no direct relationship between a customer and his answers how do you know which
    answers are a customers?

  13. #13
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: database design question

    That looks spot on to me.

    As a handy hint when you're creating diagrams like that, try and lay it out so all the relationships point down (ie they have the key at the top). This will make them a little easier to read and, also, if you can't arrange them with the relationships pointing down it means you're created a circular refernce (which is very bad)

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405

    Re: database design question

    cheers funkydexter. i'll give it a go.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width