Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Architecture question

Author  Topic 

gsnk
Starting Member

24 Posts

Posted - 2002-05-20 : 17:22:16
I'm working with a questionnaire tool right now and the question arose how to implement the answer table. I don't need to go into too much detail but the gist of it is that I think that all possible answers (Yes/No, Integers, or Strings) can be saved in a VARCHAR(1500) field. For example:

CREATE TABLE tbAnswers (
AnswerID INT NOT NULL ,
QuestionID INT NOT NULL ,
UserID INT NOT NULL ,
Answer VARCHAR (1500) NULL ,
DateCreated DATETIME NULL
)

So, regardless of whether the answer is a bit, int, char(20), or char(1500) it will end up in the same field.

Does anybody have some input and/or thoughts on that?

Thanks.

Gero

Edited by - gsnk on 05/20/2002 17:22:38

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2002-05-20 : 18:08:07
Gero,

A couple of cents...

You should also add a AnswerType column to indicate what type the value is..

Create a view for each AnswerType where you can Cast the strings to there relevant type. That way you should be able to treat each AnswerType as if it really was a bit, integer etc.. Good for aggregations, reports etc...

HTH

DavidM

"SQL-3 is an abomination.."
Go to Top of Page

gsnk
Starting Member

24 Posts

Posted - 2002-05-21 : 12:00:35
quote:

You should also add a AnswerType column to indicate what type the value is..



I'm already doing that... ;)

The tbAnswers table is a bit longer than indicated above. Thanks for the U$ 0.02, though...

Gero

Go to Top of Page

M.E.
Aged Yak Warrior

539 Posts

Posted - 2002-05-21 : 12:21:14
Well, of the stuff you've posted it's looking good.
1 change
DateCreated DATETIME NULL
I'd change this so that it's default value is getdate() and make it so it can't hold nulls. It will just ensure that you always have a date/time with all entries.


Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-05-21 : 14:33:31
Are these answers supposed to be a 'lookup' table of all valid answers to questions or are they any freeform responses that a user may enter?

<O>
Go to Top of Page

gsnk
Starting Member

24 Posts

Posted - 2002-05-22 : 15:20:39
They are both. Or better, there are text fields, textarea, dropdown, multi-selects, etc, etc... that can be used to fill that "Answer" column. To answer your question: free text input as well as look-up values (though, not the id but the actual value would be stored).

Hope that makes sense

Gero

**It's better to light a candle than to curse the darkness.**
Go to Top of Page
   

- Advertisement -