Search code examples
databasevotingvoting-system

Database design for voting


I am implementing a voting feature to allow users to vote for their favourite images. They are able to vote for only 3 images. Nothing more or less. Therefore, I am using checkboxes to do validation for it. I need to store these votes in my database.

Here is what i have so far :

|voteID | name| emailAddress| ICNo |imageID

(where imageID is a foreign key to the Images table)

I'm still learning about database systems and I feel like this isn't a good database design considering some of the fields like email address and IC Number have to be repeated.

For example,

|voteID | name|   emailAddress     |   ICNo      |  imageID
   1      BG    [email protected]    G822A28A          10
   2      BG    [email protected]    G822A28A          11
   3      BG    [email protected]    G822A28A          12
   4      MO    [email protected]   G111283Z          10 

Solution

  • You have three "things" in your system - images, people, and votes.

    An image can have multiple votes (from different people), and a person can have multiple votes (for different images).

    One way to represent this in a diagram is as follows:

    Object relationships

    So you store information about a person in one place (the Person table), about Images in one place (the Images table), and Votes in one place. The "chicken feet" relationships between them show that one person can have many votes, and one image can have many votes. ("Many" meaning "more than one").