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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:03:25+00:00 2026-05-28T07:03:25+00:00

This is more of a design problem then a programming one. I have a

  • 0

This is more of a design problem then a programming one.

I have a table where I store details about retail products:

Name    Barcode    BarcodeFormat  etc...
---------------------------------------- 

(Name, Barcode, BarcodeFormat) are three columns will uniquely identify a record in the table (Candidate Key). However, I have other tables that need a FK on this one. So I introduced an auto_increment column itemId and made that the PK.

My question is – should I have the PK as (itemId, Name, Barcode, BarcodeFormat) or would it be better to have PK(itemId) and UNIQUE(Name, Barcode, BarcodeFormat).

My primary concern is performance in terms of INSERT and SELECT operations but comments on size are also welcome.

I’m using an innodb table with mysql

  • 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-28T07:03:25+00:00Added an answer on May 28, 2026 at 7:03 am

    Definitely: PK(itemId) and UNIQUE(Name, Barcode, BarcodeFormat).

    • You don’t want the hassle of using a multi-part key for all your joins etc
    • You may one day have rows without barcode values which then won’t be unique, so you don’t want uniqueness hard-wired into your model (you can easily drop the unique without breaking any relationships etc)
    • The constraint on uniqueness is a business-level issue, not a database entity one: You’ll always need a key, but you may not always need the business rule of uniqueness
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is more UI/Design-ish than hard-core programming is. Background: I've been coding in
It seems the more I talk about this problem the better I understand it.
I am programming in Java but this is a more of a design question
this is more a design question. Suppose you have many beans A, B, C....
This is more of a design question that others may have had similar experience
This is a question more about best practices/design patterns than regexps. In short I
I have a label on my asp.net page, it looks like this: more info
This is more of a syntax question I'm trying to write a store procedure
I am having a tough time with this design problem and would appreciate any
I have a question that is more in the realm of design, than implementation.

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.