[MS SQL] 實作問卷調查結果交叉分析
問卷調查ER圖如下: 圖1: 簡易的問卷調查ERD 接下來根據此ERD,實作調查結果交叉分析表: 首先,請根據ERD,分別建立四個資料表(Table): Survey_Survey_Main、Survey_Subject、Survey_Answers、Survey_Result --建立資料表 Survey_Survey_Main SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Survey_Survey_Main]( [ID] [int] IDENTITY(1,1) NOT NULL, [SurveyName] [nvarchar](50) NULL, CONSTRAINT [PK_Survey_Survey_Main] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO --建立資料表 Survey_Subject SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Survey_Subject]( [ID] [int] IDENTITY(1,1) NOT NULL, [MainID] [int] NOT NULL, [Subject] [nvarchar](50) NULL, CONSTRAINT [PK_Survey_Subject] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO --建