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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:04:38+00:00 2026-05-26T17:04:38+00:00

While I’ve been working with querying SQL databases for a while, I’m still quite

  • 0

While I’ve been working with querying SQL databases for a while, I’m still quite the novice at actually building good tables. One thing I often struggle is with primary keys.

In a table I’m creating now for logging errors on some alarm equipment, I need 5 columns.
The park and code columns uniquely identifies a site (although the park column is atm. not used). Then there is a serial column identifying the equipment in question, and an error containing the error code. Lastly there is a timestamp for when an error is logged.

Each site have several different pieces of equipment, and an piece of equipment may report several errors. When an error is corrected, the row is removed from the table.

Thus to uniquely identify an error, we need to check park, code, serial and fault.
All of these seems like good candidates for indexes based on the queries likely to be run. However it doesn’t seem right to me to define all of these as an combined primary key, they are after all almost all the columns in the table!

I’ve several times struggled with similar problems, and I’ve never felt I’ve found a good solution. Anyone can suggest some good practices for tables like this, where most (or even all) the columns are needed to uniquely identify a row?

  • 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-26T17:04:38+00:00Added an answer on May 26, 2026 at 5:04 pm

    A lot of people will just tell you to add an id number to that table, and make it the primary key.

    I’m not one of those people.

    If the columns {park, code, serial, fault} are necessary to uniquely identify a row, and thereby to prevent duplicates, then the dbms needs to know that. You inform the dbms of that requirement in one of two ways.

    • PRIMARY KEY (park, code, serial, fault)
    • NOT NULL UNIQUE (park, code, serial, fault)

    In some circumstances, it makes sense to use a smaller surrogate key (an id number) as the primary key. That doesn’t relieve you of the responsibility for informing the dbms of the true state of affairs. (With NOT NULL UNIQUE (park, code, serial, fault).) I don’t think this applies to your situation, though.

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

Sidebar

Related Questions

while working in c/c++, 1.cin/cout or 2.scanf/printf , which one of both , will
While working on an universal binary for iPhone / iPad, I've been asking my
While working in a Java app, I recently needed to assemble a comma-delimited list
While in the final throws of upgrading MS-SQL Server 2005 Express Edition to MS-SQL
While I search this one out on my own, may be some one could
While Ive seen plenty of examples in PHP, can't seem to find one in
While working with the sockets library in python 2.7, I am encountering an issue
While working with project I upgraded the version of IOS SDK 3.2 to 4.2
While working with Akka, I have implemented a simple command line app. But Akka
While I was trying to uplaod file using php on windows machine its working

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.