Alberto, although two questions have exactly the same text and from the point of view of the user they are the same, at the level of database they do not need to be the same question.
Follow the table creation script for SQL-Server:
CREATE SCHEMA [quiz]
GO
/****** Object: Table [quiz].[Pergunta] Script Date: 1/13/2016 9:06:19 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [quiz].[Pergunta](
[PerguntaID] [int] IDENTITY(1,1) NOT NULL,
[Descricao] [varchar](255) NOT NULL,
CONSTRAINT [PK_Pergunta] PRIMARY KEY CLUSTERED
(
[PerguntaID] 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
SET ANSI_PADDING OFF
GO
/****** Object: Table [quiz].[Resposta] Script Date: 1/13/2016 9:06:19 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [quiz].[Resposta](
[RespostaID] [int] NOT NULL,
[PerguntaID] [int] NOT NULL,
[Descricao] [varchar](255) NOT NULL,
[PerguntaProximaID] [int] NULL,
CONSTRAINT [PK_Resposta] PRIMARY KEY CLUSTERED
(
[RespostaID] 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
SET ANSI_PADDING OFF
GO
/****** Object: Index [IX_Resposta_PerguntaID] Script Date: 1/13/2016 9:06:19 AM ******/
CREATE NONCLUSTERED INDEX [IX_Resposta_PerguntaID] ON [quiz].[Resposta]
(
[PerguntaID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object: Index [IX_Resposta_PerguntaProximaID] Script Date: 1/13/2016 9:06:19 AM ******/
CREATE NONCLUSTERED INDEX [IX_Resposta_PerguntaProximaID] ON [quiz].[Resposta]
(
[PerguntaProximaID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
ALTER TABLE [quiz].[Resposta] WITH CHECK ADD CONSTRAINT [FK_Resposta_Pergunta] FOREIGN KEY([PerguntaID])
REFERENCES [quiz].[Pergunta] ([PerguntaID])
GO
ALTER TABLE [quiz].[Resposta] CHECK CONSTRAINT [FK_Resposta_Pergunta]
GO
ALTER TABLE [quiz].[Resposta] WITH CHECK ADD CONSTRAINT [FK_Resposta_Pergunta_Proxima] FOREIGN KEY([PerguntaProximaID])
REFERENCES [quiz].[Pergunta] ([PerguntaID])
GO
ALTER TABLE [quiz].[Resposta] CHECK CONSTRAINT [FK_Resposta_Pergunta_Proxima]
GO
If you prefer, the Table Pergunta
may have a column ProximaPerguntaID
which will serve as default value for the column ProximaPerguntaID
table Resposta
is not informed.
Do you have anything you’ve already done? It shows there. You essentially need to have one or more columns that determine(m) dependency. This column(s) needs(s) to indicate what is the question and the answer that needs to have been answered for that question to be asked. It is possible to do this in the answers as well, but I find it unlikely that it is useful to modify the possible answers, it is easier to choose only which question is conditional. Just like you’re doing. If you have more complex situations to determine which questions will be activated, then it complicates well and only with more details to answer.
– Maniero