前回Q&Aシステムを行ったときは、複数ページの質問からなる調査を処理していました。回答は、チェックボックス、ラジオボタン、複数選択用の選択ボックス、またはテキスト入力(オプションで整数値に制限)の場合があります。
テーブルは次のようになりました。
-- 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程度で許可されるテーブル数の制限に達し続けました。