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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:04:08+00:00 2026-05-10T19:04:08+00:00

When I am creating a new database table, what factors should I take into

  • 0

When I am creating a new database table, what factors should I take into account for selecting the primary key’s data type?

  • 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. 2026-05-10T19:04:09+00:00Added an answer on May 10, 2026 at 7:04 pm

    Sorry to do that, but I found that the answers I gave to related questions (you can check this and this) could apply to this one. I reshaped them a little bit…

    You will find many posts dealing with this issue, and each choice you’ll make has its pros and cons. Arguments for these usually refer to relational database theory and database performance.

    On this subject, my point is very simple: surrogate primary keys ALWAYS work, while Natural keys MIGHT NOT ALWAYS work one of these days, and this for multiple reasons: field too short, rules change, etc.

    To this point, you’ve guessed here that I am basically a member of the uniqueIdentifier/surrogate primary key team, and even if I appreciate and understand arguments such as the ones presented here, I am still looking for the case where ‘natural’ key is better than surrogate …

    In addition to this, one of the most important but always forgotten arguments in favor of this basic rule is related to code normalization and productivity:

    each time I create a table, shall I lose time

    1. identifying its primary key and its physical characteristics (type, size)
    2. remembering these characteristics each time I want to refer to it in my code?
    3. explaining my PK choice to other developers in the team?

    My answer is no to all of these questions:

    1. I have no time to lose trying to identify ‘the best Natural Primary Key’ when the surrogate option gives me a bullet-proof solution.
    2. I do not want to remember that the Primary Key of my Table_whatever is a 10 characters long string when I write the code.
    3. I don’t want to lose my time negotiating the Natural Key length: ‘well if You need 10 why don’t you take 12 to be on the safe side?’. This ‘on the safe side’ argument really annoys me: If you want to stay on the safe side, it means that you are really not far from the unsafe side! Choose surrogate: it’s bullet-proof!

    So I’ve been working for the last five years with a very basic rule: each table (let’s call it ‘myTable’) has its first field called 'id_MyTable' which is of uniqueIdentifier type. Even if this table supports a ‘many-to-many’ relation, where a field combination offers a very acceptable Primary Key, I prefer to create this 'id_myManyToManyTable' field being a uniqueIdentifier, just to stick to the rule, and because, finally, it does not hurt.

    The major advantage is that you don’t have to care anymore about the use of Primary Key and/or Foreign Key within your code. Once you have the table name, you know the PK name and type. Once you know which links are implemented in your data model, you’ll know the name of available foreign keys in the table.

    And if you still want to have your ‘Natural Key’ somewhere in your table, I advise you to build it following a standard model such as

    Tbl_whatever     id_whatever, unique identifier, primary key    code_whatever, whateverTypeYouWant(whateverLengthYouEstimateTheRightOne), indexed    ..... 

    Where id_ is the prefix for primary key, and code_ is used for ‘natural’ indexed field. Some would argue that the code_ field should be set as unique. This is true, and it can be easily managed either through DDL or external code. Note that many ‘natural’ keys are calculated (invoice numbers), so they are already generated through code

    I am not sure that my rule is the best one. But it is a very efficient one! If everyone was applying it, we would for example avoid time lost answering to this kind of question!

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

Sidebar

Related Questions

I'm creating sign_up and sign_in page and data that type into editview will be
Sometimes the overhead of creating a new model type is annoying. In these cases,
I create new database with utf8_general_ci collation, create test table also with utf8_general_ci collation,
Is there an easy way of dumping a SQLite database table into a text
I'm fairly new to database design, but I understand the fundamentals. I'm creating a
I've changed column length manually in my previous database. But after creating new database
I am creating a new XDocument from a table. I have to validate the
I'm new in creating database in Microsoft Access, I'm trying to figure out how
Using table per type inheritance is it possible to have the same data with
I'm grabbing field row from one table and creating a new table for each

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.