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

The Archive Base Latest Questions

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

What is better generating Primary Keys on the database or generating them in application

  • 0

What is “better” generating Primary Keys on the database or generating them in application code, specifically when using GUID/UniqueIdentifier datatype for the keys.

I have read up on the difference between using Guid’s and int data types, and it sounds like Guids are feasable for so called “generating offline”.

E.g.

instead of having a NEWID() contstraint in the database, In one project (where we are using Entity Framework) we use in the application code Guid.NewGuid() to generate the PK when inserting data.

Is this a bad approach ?

My concerns are:

  • Database indexes: Database performance because Id’s might not be sequential
  • The one in 64 billion chance that the key is already used. (considering that the application will not be enormous but may need room to grow)
  • Perhaps there are other disadvantages ?
  • 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-31T05:26:55+00:00Added an answer on May 31, 2026 at 5:26 am

    well actually, GUID could be sequential from SQL Server 2005. There is a function in named NEWSEQUENTIALID() , link here

    Creates a GUID that is greater than any GUID previously generated by
    this function on a specified computer since Windows was started. After
    restarting Windows, the GUID can start again from a lower range, but
    is still globally unique. When a GUID column is used as a row
    identifier, using NEWSEQUENTIALID can be faster than using the NEWID
    function. This is because the NEWID function causes random activity
    and uses fewer cached data pages. Using NEWSEQUENTIALID also helps to
    completely fill the data and index pages.

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

Sidebar

Related Questions

In C#, I have an array of integers, that represent the primary keys of
I have a CMS generating a basic navigation using a UL. Each first-level LI
I'm generating code dynamically, currently using String.Format and embedding placeholders - but reformatting the
As a rule is it better to use native primary keys (ie existing columns
So I have some php code that is generating links, and for the url
I have just started using sprite sheets in Cocos2D in an attempted to better
My question is what is better to use in generating columns in SQL. Should
I have a database with a lot of users in it. Those users belong
For generating random string i written code like this But if the function is
I'm generating a random number between min and max with this code: return min

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.