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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:37:38+00:00 2026-05-19T22:37:38+00:00

So am a few months into a project and I realize that the PKs

  • 0

So am a few months into a project and I realize that the PKs I chose might not fit enhancement planned for version 2. I also find that moving to either a compound PK or a surrogate PK will require a code change to virtually every part of the system.

For instance my DAL has GetPerson(string PersonID) methods that will need to take other types of parameters to function. Also most of the web pages take querystrings with PKs embedded in them (i.e. /GetPerson?PersonID=BILL)

It got me thinking that I wish I implemented some encapsulation where I protected myself from PK changes. Have abstract methods for placing and reading a PK from a querystring. Likewise instead of passing native types to the DAL, pass a PersonPK object and hide the implementation.

In theory I like the idea, I’m just not sure in practice, it’s possible to prevent this from becoming a “leaky abstraction”. For instance, once it’s time to generate DB calls, I have to crack open the PK object. And there still is going to be dozens of statements to rewrite.

So to my question….Does anybody successfully use PK abstraction in their projects? Has it saved you time? What are the keys to implementing this successfully?

EDIT:
Some of the replies suggest to me that I wasn’t clear on something.

I was never suggesting that I create some abstract primary key column in the database. I was merely contemplating that the Business Logic and front end code be designed in a way that was resistant to PK refactoring.

  • 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-19T22:37:38+00:00Added an answer on May 19, 2026 at 10:37 pm

    I wish I implemented some
    encapsulation where I protected myself
    from PK changes.

    The encapsulation you’re looking for is the simple use of a surrogate key. That is: an identifier generated by the database (not the end user) to uniquely identify a row of data. They are usually auto-incrementing integers and sometimes GUIDs.

    My rule of thumb: If a piece of data stored in the database has the slimmest chance of even appearing in front of the end user (much less being available for editing) then DO NOT use it as a primary key! An example: An email address can uniquely identify a user in a system. Yes, it can be used as a pkey but!

    • What if the user wants to change his/her address? You have to update simultaneously every table where the email address is the foreign key!
    • Consider the index bloat on each table that contains that primary key!
    • Consider the performance hit of comparing two strings instead of two integers to link two rows in a simple join!

    Many devs go as far as automatically creating a surrogate key for every table in the db. This is actually good practice, especially if surrogate keys don’t feel “natural” to you right away.

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

Sidebar

Related Questions

We are a few months into a green-field project to rework the Logic and
I've been getting into Ruby over the past few months, but one thing that
A few months ago when I looked into HTTP-live streaming I thought I found
A few months ago, I was working on a PHP project in Aptana Studio.
Its few months i am into the C#... and i am listening Asynchronous ...
I'm running an SSIS package that I made a few months ago, and ran
When I learned MIPS assembly a few months ago, a question popped into my
I've run into this behavior after using JS for a few months. I'm very
I was working for a few months on the project without even noticing this,
I solved Project Euler's Problem 67 a few months back with a wildly inefficient

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.