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

  • SEARCH
  • Home
  • 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 365571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:32:59+00:00 2026-05-12T13:32:59+00:00

I am making a webapp right now and I am trying to get my

  • 0

I am making a webapp right now and I am trying to get my head around the database design.

I have a user model(username (which is primary key), password, email, website)
I have a entry model(id, title, content, comments, commentCount)

A user can only comment on an entry once. What is the best and most efficient way to go about doing this?

At the moment, I am thinking of another table that has username (from user model) and entry id (from entry model)

   **username    id**
    Sonic        4
    Sonic        5
    Knuckles     2
    Sonic        6
    Amy          15
    Sonic        20
    Knuckles     5
    Amy          4

So then to list comments for entry 4 it searches for id=4.

On a side note:
Instead of storing a commentCount, would it be better to calculate the comment count from the database each time when needed?

  • 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-05-12T13:33:00+00:00Added an answer on May 12, 2026 at 1:33 pm

    Your design is basically sound. Your third table should be named something like UsersEntriesComments, with fields UserName, EntryID and Comment. In this table, you would have a compound primary key consisting of the UserName and EntryID fields; this would enforce the rule that each user can comment on each entry only once. The table would also have foreign key constraints such that UserName must be in the Users table, and EntryID must be in the Entries table (the ID field, specifically).

    You could add an ID field to the Users table, but many programmers (myself included) advocate the use of “natural” keys where possible. Since UserNames must be unique in your system, this is a perfectly valid (and easily readable) primary key.

    Update: just read your question again. You don’t need the Comments or the CommentsCount fields in your Entries table. Comments would properly be stored in the UsersEntriesComments table, and the counts would be calculated dynamically in your queries (saving you the trouble of updating this value yourself).

    Update 2: James Black makes a good point in favor of not using UserName as the primary key, and instead adding an artificial primary key to the table (UserID or some such). If you use UserName as the primary key, allowing a user to change their user name is more difficult, as you have to change the username in all the related tables as well.

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

Sidebar

Related Questions

I have a webapp I'm making that stores user information, and their preferences regarding
I am making a webapp. I have a fairly basic question about javascript performance.
I am practicing making a web app which tries to read the user's twitter
I have AlivePDF with Flex, making a webapp. I've got version 1.5 of AlivePDF
I'm trying to make a webapp. The application I am making for myself to
I'm making a dictionary webapp. The user will search for words. Would it be
I'm developing a Java webapp using Spring, Spring Security, Tomcat and MySQL. Right now
I'm making a webapp for iOS. When I make a dropdown list with the
We are making a Ruby On Rails webapp where every customer gets their own
Spring 3.1 Tomcat 6.* I'm working on making a Spring 3.1 webapp, authenticating with

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.