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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T00:26:54+00:00 2026-05-21T00:26:54+00:00

Lets say that I have a table where I want to record usernames. At

  • 0

Lets say that I have a table where I want to record usernames. At minimum the table should have two columns : UserID and Name. Typically I see people put a primary key on UserID turn on auto increment and call it day.

However that seems wrong to me, shouldn’t the key be a composite key between both columns? As we don’t want the username to ever be repeated. We want to also keep UserID so that we don’t break existing references to a particular user if their name changes.

What I’m getting at is it seems like many people default to an ID column with a PK on it for every table they make without making sure that key enforces uniqueness on other columns as well.

With that being said, am I correct in stating that a table should always have an ID column for referencing, but it is equally important to use composite primary keys?

  • 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-21T00:26:55+00:00Added an answer on May 21, 2026 at 12:26 am

    No, you don’t want it as a composite key; that means that the combination is the primary key, so you could then have different names on the same ID, and different ID’s on the same name.

    I.E.:

    UserID    Name
    -----------------
    1         BobaFett
    2         JarJar
    1         JarJar
    2         BobaFett
    

    In the absence of any other constraints, making the primary key a composite of (UserID, Name) would make the previous data perfectly legal.

    Your UserID column is a surrogate key; I’ll leave the discussion about the wisdom of using surrogate keys vs. natural keys (your Name column is a natural candidate key) for another time, but if you want to keep your design the way it is now, then you should leave UserID as the primary key but also add a unique constraint on Name. This will prevent the same name from being attached to multiple records.

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

Sidebar

Related Questions

Lets say that I have only DHT (distributed hash table) implemented (in Python), and
Lets say I have one table called REVIEWS This table has Reviews that customers
Lets say I have a table in MySQL called articles, that has a column
Lets say I have two tables - Cat and Cat owner that are linked
For examples sake, lets say I have a table containing these columns ID (primary
So lets say I have a table that looks something like this: ItemName ProductType
lets say I have two tables: Persons (P_Id, Name) and Orders (O_Id, OrderNo, P_Id)...
Lets say that I have a table with a timestamp column full of records
Let's say that I want to insert a record in a table. Each record
Lets say that I have three tables, customers, orders and orderDetails. I'm doing this:

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.