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 9212923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:38:01+00:00 2026-06-18T01:38:01+00:00

I’m referring to this SO-question . Here, in the first answer, it’s said that

  • 0

I’m referring to this SO-question. Here, in the first answer, it’s said that

UNIQUE refers to an index where all rows of the index must be unique. That is, the same row may not have identical non-NULL values for all columns in this index as another row. As well as being used to speed up queries, UNIQUE indexes can be used to enforce restraints on data, because the database system does not allow this distinct values rule to be broken when inserting or updating data.

As my english is not the best, I wonder what it means, that

the same row may not have identical non-NULL values for all columns in this index as another row

To quickly connect this with my acutal problem, here is my scenario. I have three tables

game(gameID, ...), PK(gameID)
player(gameID, playerName, ...), PK(gameID, playerName), FK(gameID)
prop(gameID, playerName, c1, c2, c3, ...) PK(gameID, playerName), FK(gameID, playerName)

Now, a player connected to a game can choose 1-n props. In such a prop, c1 - c3 are representing playing card values, more exact {1,2,3, …, T, J, Q, K, A}.

Such a combination of three cards can consist of same values, but a combination can only be choosen once in a game. E.g. a player can choose {2,2,3} and {A,2,3}, but then, in that game, no other player can pick the same combination again.

Now to return on my preamble, the three elements c1, c2, c3 are not declared UNIQUE in the CREATE TABLE statement (otherwise the first combination in the example would not be possible). Does that mean I cannot use UNIQUE(gameID, c1, c2, c3) as a constraint to assure uniqueness of a combination in a game? Is this a good example to use INDEX(gameID, c1, c2, c3)? What is the difference in using the two variants in my particular case?

Finally the CREATE TABLE statement of that third table would be

create table prop(
    gameID  INTEGER NOT NULL,
    playerName  VARCHAR(25) NOT NULL,
    isBB    BOOLEAN NOT NULL DEFAULT FALSE,
    card1   VARCHAR(1) NOT NULL,
    card2   VARCHAR(1) NOT NULL,
    card3   VARCHAR(1) NOT NULL,
    PRIMARY KEY (gameID, playerName),
    FOREIGN KEY (gameID, playerName) REFERENCES player(gameID, playerName) ON DELETE CASCADE,
    UNIQUE(gameID, c1, c2, c3) /* OR INDEX(gameID, c1, c2, c3)?

)ENGINE=INNODB;
  • 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-18T01:38:02+00:00Added an answer on June 18, 2026 at 1:38 am

    Indexes are used to speed up the searches in the database. Unique constraints on the other hand, enforce rules over the rows in the database (in your example, no two rows will have same values for ‘gameID, c1, c2, c3’ columns altogether.

    You can have index on gameID to speed up queries like WHERE gameID = ?. But that doesn’t guarantee that you’ll have only 1 row having, let’s say gameID = 1. If you need to have such a constraint, then UNIQUE constraint is what you need (for id fields, primary key is a better option since it combines uniqueness and indexing together).

    To answer your specific questions:

    Does that mean I cannot use UNIQUE(gameID, c1, c2, c3) as a constraint to assure uniqueness of a combination in a game?

    If you do this then those combinations will be unique per game.

    Is this a good example to use INDEX(gameID, c1, c2, c3)?

    This is also a good example if you’ll frequently search for combinations in a game.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
Let's say I'm outputting a post title and in our database, it's Hello Y’all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.