Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7727623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:30:18+00:00 2026-06-01T05:30:18+00:00

I have a problem with my site. The site has multiple entities: Articles, Posts,

  • 0

I have a problem with my site. The site has multiple entities: Articles, Posts, Reviews … orund 6 types. Now I am introducing the possibility for a user to rate an item (it can be any of these entities)

I created a table Votes (int Id primary key, int ItemId, nvarchar(30) Ip, datetime Timestamp, int VoteValue). Here I will store all votes and their ips.

My problem is that I must have ItemID unique … but my database already have items of various types having the same id. All tables started the ids from 0. What options do you see for my design in order to be able to store all votes in a single table?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T05:30:19+00:00Added an answer on June 1, 2026 at 5:30 am

    Your approach is trying to assign multiple meanings to the field “ItemId”, which will lead to the issues you are encountering. If I were to see “9500” in that field, how would I know what that means?

    I would suggest dropping the ItemId field and creating “crosswalk” tables between Votes and the other entities.

    For example, your entities:

    +-----------+
    | Articles  |
    +-----------+
    | ArticleId | PK
    | ~ snip ~  |
    +-----------+
    
    +-----------+
    | Posts     |
    +-----------+
    | PostId    | PK
    | ~ snip ~  |
    +-----------+
    

    … etc ….

    Your votes table:

    +-----------+
    | Votes     |
    +-----------+
    | VoteId    | PK
    | ~ snip ~  |
    +-----------+
    

    Your “crosswalk” tables:

    +--------------+
    | ArticleVotes |
    +--------------+
    | ArticleId    | PK, FK to Articles
    | VoteId       | PK, FK to Votes
    +--------------+
    
    +--------------+
    | PostVotes    |
    +--------------+
    | PostId       | PK, FK to Posts
    | VoteId       | PK, FK to Votes
    +--------------+
    

    Note that in your crosswalk tables, you would create a composite primary key consisting of both the FK references to the appropriate entities, thereby ensuring uniqueness.

    In my experience, this is an appropriate normalized approach to the domain you describe.

    In querying, to get the votes for the Articles (for example) simply INNER JOIN Articles through ArticleVotes to Votes. To get all Votes, simply query Votes.

    Additionally, I would suggest creating an IPAddresses table and FKing to that in your Votes table to reduce redundancy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to build a site that has multiple color options but it also
I have an IIS website running an ASP.NET site but it has multiple applications
I have a problem with my site. I want that the shadow stops at
I have a problem on my site's login page in IE7 browser. One of
I have a problem in a site that I am trying to develop Sometimes
i have this annoying problem with my site where, when you click on a
I have a problem with my search on my site I don't understand why
I have a problem with a oneway web method that open a moss site
I have a problem with Drupal uploads path when in a multi language site.
I have a problem with the FreeTextBox rich Text Editor in my ASP.NET site.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.