我需要在我的SQL(Azure)服务器中构建一个良好的“问题和答案”结构。 我正在考虑这样做:
table question
id float (we could have lots of questions, so that's why float and don't int)
nvarchar question (question can vary in size of characters)
id_answer float
table answer
id float
nvarchar answer
您认为这是一个好方法吗? 我必须考虑不同类型的问题,我可能会有这样的问题:
question: Who invented the lamp ?
answer: Thomas Edson
question: Thomas Edson invested the lamp ?
answer: No. (true or false)
你们知道其他一些好方法吗?
感谢。
答案 0 :(得分:1)
我上一次做Q&它处理的系统由多页问题组成的调查。答案可以是复选框,单选按钮或用于多项选择或文本输入的选择框(可选择限制为整数值)。
表格看起来像这样:
-- There are pages of questions.
CREATE TABLE [dbo].[Pages] (
[PageId] [int] IDENTITY (1, 1) NOT NULL ,
[Name] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Description] [varchar] (1024) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[PageTypeId] [int] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[PageTypes] (
[PageTypeId] [int] IDENTITY (1, 1) NOT NULL ,
[Name] [varchar] (32) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Description] [varchar] (1024) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[TargetPages] (
[QuestionId] [int] NOT NULL ,
[PageId] [int] NOT NULL ,
[Rank] [int] NOT NULL
) ON [PRIMARY]
GO
-- Questions have input fields. Perhaps a text entry, perhaps several multiple-guess choices.
CREATE TABLE [dbo].[Questions] (
[QuestionId] [int] IDENTITY (1, 1) NOT NULL ,
[StartDate] [datetime] NOT NULL ,
[EndDate] [datetime] NOT NULL ,
[Description] [varchar] (1024) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Filespec] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[Fields] (
[QuestionId] [int] NOT NULL ,
[FieldId] [int] IDENTITY (1, 1) NOT NULL ,
[FieldName] [varchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[InputTypeId] [int] NOT NULL ,
[Description] [varchar] (256) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[InputTypes] ( -- Roughly: checkbox, radio button, text, textarea or select list.
[InputTypeId] [int] IDENTITY (1, 1) NOT NULL ,
[InputTypeName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Choices] [bit] NOT NULL ,
[NumericValue] [bit] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[Choices] ( -- Defines radio button or select list choices for multiple choice questions.
[FieldId] [int] NOT NULL ,
[cName] [varchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[cValue] [varchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Rank] [int] NOT NULL
) ON [PRIMARY]
GO
-- Then we have the answers supplied by users.
CREATE TABLE [dbo].[Inquiries] (
[InquiryId] [int] IDENTITY (1, 1) NOT NULL ,
[UserId] [int] NOT NULL ,
[QuestionId] [int] NOT NULL ,
[dTimestamp] [datetime] NOT NULL ,
[ResponseSequence] [int] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[Users] (
[UserId] [int] IDENTITY (1, 1) NOT NULL ,
[Username] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[Responses] ( -- Multiple choice.
[InquiryId] [int] NOT NULL ,
[FieldId] [int] NOT NULL ,
[FieldValue] [varchar] (1024) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[IntegerResponses] ( -- User supplied integer or multiple choice value.
-- NB: Checkbox values are handled thusly: a row here indicates the box was checked, no row is unchecked. The value is meaningless.
[InquiryId] [int] NOT NULL ,
[FieldId] [int] NOT NULL ,
[FieldValue] [int] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[TextResponses] ( -- User supplied text.
[InquiryId] [int] NOT NULL ,
[FieldId] [int] NOT NULL ,
[FieldValue] [varchar] (1024) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
exec sp_addextendedproperty N'MS_Description', N'1 ==> Values are in the Choices table.', N'user', N'dbo', N'table', N'InputTypes', N'column', N'Choices'
GO
exec sp_addextendedproperty N'MS_Description', N'1 ==> Values are numeric.', N'user', N'dbo', N'table', N'InputTypes', N'column', N'NumericValue'
GO
查询一直在SELECT
允许的表数限制,256左右。
答案 1 :(得分:1)
我绝对不会去浮动,因为它是一种非精确且非确定性的数据类型。尝试使用bigint代替。 据我所知,浮点数很难被放入索引中。不知道sql数据库(azure)和/或sql server 2012虽然
答案 2 :(得分:0)
这取决于您的问题将如何构建。
如果您有自由文本输入,只有一个正确的答案,那么将问题与答案分开是没有意义的,因此在问题表中有一个答案字段。但是你依赖正确的拼写等等。
如果您计划对问题进行多项选择答案,那么您希望在Answers表中使用QuestionID,而不是上面的设置。
你可以在问题和答案之间另外有一个表,所以答案可以是对多个问题的答案。
你的身份证想要成为一个整体,而不是花车;如果超出整数范围,请使用uniqueidentifiers。浮动不是精确