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 2005 Forums
 Transact-SQL (2005)
 Survey

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2008-09-04 : 11:04:40
Hello,

I am creating a survey system and I have the following:

-- Polls
create table dbo.Polls
(
PollID uniqueidentifier not null
constraint PK_Poll primary key clustered,
CreatedAt datetime null,
IsActive bit null,
Question nvarchar(200) null,
UpdatedAt datetime null
)

-- Options
create table dbo.Options
(
OptionID uniqueidentifier not null
constraint PK_Poll primary key clustered,
PollID uniqueidentifier not null,
CreatedAt datetime null,
IsActive bit null,
Answer nvarchar(200) null,
UpdatedAt datetime null,
constraint FK_Options_Pools
foreign key(PollID)
references dbo.Polls(PollID)
on delete cascade,
)


I think in this moment everything is fine. Is it?

But how should I track the votes?
Should I add a column Votes to Options table or maybe create a new Votes table?

What is the correct approach?

Thanks,
Miguel

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-04 : 11:08:24
i think you should include a new votes table for that with pollid and optionid as fks
Go to Top of Page

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2008-09-04 : 11:33:17
But do I need to related it to Polls?

Options is already related to Polls so if I relate a vote to an option why should I related all to Polls?

Anyway, this is what I am thinking:

create table dbo.Votes
(
VoteID uniqueidentifier not null
constraint PK_Poll primary key clustered,
OptionID uniqueidentifier not null,
constraint FK_Votes_Options
foreign key(OptionID)
references dbo.Options(OptionID)
on delete cascade,
)


Am I wrong? This way to get votes I would count the records in this table related to each option in Options only for a given PollID.

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-04 : 11:39:22
quote:
Originally posted by shapper

But do I need to related it to Polls?

Options is already related to Polls so if I relate a vote to an option why should I related all to Polls?

Anyway, this is what I am thinking:

create table dbo.Votes
(
VoteID uniqueidentifier not null
constraint PK_Poll primary key clustered,
OptionID uniqueidentifier not null,
constraint FK_Votes_Options
foreign key(OptionID)
references dbo.Options(OptionID)
on delete cascade,
)


Am I wrong? This way to get votes I would count the records in this table related to each option in Options only for a given PollID.




yup. it looks fine. You can still link to options and from there to polls and find out poll for which vote was gievn.
Go to Top of Page

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2008-09-04 : 12:12:39
Yes, that was exactly what I was thinking.

Thanks,
Miguel
Go to Top of Page
   

- Advertisement -