Skip to main content
deleted 28 characters in body
Source Link
Paul White
  • 90.3k
  • 30
  • 424
  • 663

Assuming a person can only submit one and only one vote, you just need teotwo tables, PlaceVotes and PostVotes, as follows

create table dbo.PlaceVotes (

Id int not null,

PlaceId int not null,

UserId int not null,

CreatedDate datetime not null,

Value int not null,

constraint unique index ux_userid (UserId, place),

constraint primary key pk_placevotes(id)

)

and create table dbo.PostVotes (

Id int not null,

PostId int not null,

UserId int not null,

CreatedDate datetime not null,

Value int not null,

constraint unique index ux_userid (UserId, postid),

constraint primary key pk_postvotes(id), as follows

)

create table dbo.PlaceVotes (
 Id int not null,
 PlaceId int not null,
 UserId int not null,
 CreatedDate datetime not null,
 Value int not null,
 constraint unique index ux_userid (UserId, place),
 constraint primary key pk_placevotes(id)
)

create table dbo.PostVotes (
 Id int not null,
 PostId int not null,
 UserId int not null,
 CreatedDate datetime not null,
 Value int not null,
 constraint unique index ux_userid (UserId, postid),
 constraint primary key pk_postvotes(id)
)

This way, the voting event is represented as one entity.

Hope this helps.

Edited after reading Miguel's comment

Assuming a person can only submit one and only one vote, you just need teo tables, PlaceVotes and PostVotes, as follows

create table dbo.PlaceVotes (

Id int not null,

PlaceId int not null,

UserId int not null,

CreatedDate datetime not null,

Value int not null,

constraint unique index ux_userid (UserId, place),

constraint primary key pk_placevotes(id)

)

create table dbo.PostVotes (

Id int not null,

PostId int not null,

UserId int not null,

CreatedDate datetime not null,

Value int not null,

constraint unique index ux_userid (UserId, postid),

constraint primary key pk_postvotes(id)

)

This way, the voting event is represented as one entity.

Hope this helps.

Edited after reading Miguel's comment

Assuming a person can only submit one and only one vote, you just need two tables, PlaceVotes and PostVotes, as follows

create table dbo.PlaceVotes (
 Id int not null,
 PlaceId int not null,
 UserId int not null,
 CreatedDate datetime not null,
 Value int not null,
 constraint unique index ux_userid (UserId, place),
 constraint primary key pk_placevotes(id)
)

create table dbo.PostVotes (
 Id int not null,
 PostId int not null,
 UserId int not null,
 CreatedDate datetime not null,
 Value int not null,
 constraint unique index ux_userid (UserId, postid),
 constraint primary key pk_postvotes(id)
)

This way, the voting event is represented as one entity.

added 327 characters in body
Source Link

Assuming a person can only submit one and only one vote, you just need one tableteo tables, VotesPlaceVotes and PostVotes, as follows

create table dbo.VotesPlaceVotes (

Id int not null,

PlaceId int not null,

UserId int not null,

CreatedDate datetime not null,

Value int not null,

constraint unique index ux_userid (UserId, place),

constraint primary key pk_placevotes(id)

)

create table dbo.PostVotes (

Id int not null,

PostId int not null,

UserId int not null,

CreatedDate datetime not null,

Value int not null,

constraint unique index ux_userid (UserId, postid),

constraint primary key pk_votespk_postvotes(id)

)

This way, the voting event is represented as one entity.

Hope this helps.

Edited after reading Miguel's comment

Assuming a person can only submit one and only one vote, you just need one table, Votes, as follows

create table dbo.Votes (

Id int not null,

PlaceId int not null,

PostId int not null,

UserId int not null,

CreatedDate datetime not null,

Value int not null,

constraint unique index ux_userid (UserId),

constraint primary key pk_votes(id)

)

This way, the voting event is represented as one entity.

Hope this helps

Assuming a person can only submit one and only one vote, you just need teo tables, PlaceVotes and PostVotes, as follows

create table dbo.PlaceVotes (

Id int not null,

PlaceId int not null,

UserId int not null,

CreatedDate datetime not null,

Value int not null,

constraint unique index ux_userid (UserId, place),

constraint primary key pk_placevotes(id)

)

create table dbo.PostVotes (

Id int not null,

PostId int not null,

UserId int not null,

CreatedDate datetime not null,

Value int not null,

constraint unique index ux_userid (UserId, postid),

constraint primary key pk_postvotes(id)

)

This way, the voting event is represented as one entity.

Hope this helps.

Edited after reading Miguel's comment

Source Link

Assuming a person can only submit one and only one vote, you just need one table, Votes, as follows

create table dbo.Votes (

Id int not null,

PlaceId int not null,

PostId int not null,

UserId int not null,

CreatedDate datetime not null,

Value int not null,

constraint unique index ux_userid (UserId),

constraint primary key pk_votes(id)

)

This way, the voting event is represented as one entity.

Hope this helps