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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:45:12+00:00 2026-05-27T19:45:12+00:00

I have to create logic for generation unique number identifier for records in database.

  • 0

I have to create logic for generation unique number identifier for records in database. id, generated in database is a separate column.

At this moment, when user calls “create record” action, I save new record, get its database id, generate record number using this id, then put it to the edit form.
Using this way means that all entity fields should be nullable to save record to database.

I don’t like this way. I know that should be better way.

Is there a better practice to generate unique number identifier? What is possibility of generating non-unique random numbers?

Thank you

  • 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-27T19:45:12+00:00Added an answer on May 27, 2026 at 7:45 pm

    The pattern that you’re using, of saving an empty record simply to get the ID, is not a good one.

    The standard approach, and the one that I’d recommend, is for Create Record to simply display an empty form (the ID at this point will typically be 0). The user fills in the form and the data is only committed to the database when the user clicks Save. The ID should be an IDENTITY column.

    A problem with your approach is that if users do not complete the form, you end up with lots of incomplete records in your database. And, of course, it makes it much more difficult to handle data validation and integrity.

    An alternative approach, if you really must display the ID to the user, is to have a separate table containing a row with a “Next Record ID” column. This column can be incremented and returned as an atomic operation and used to populate the ID of your new record. You still don’t create the real record, just increment this “Next Record ID” in your Create Record action. Using this approach, you can use the same approach for multiple entities by having separate rows for each in this “Record IDs” table. Bear in mind that if the user does not ultimately save the record to the database, an ID will still have been ‘used up’. The numbers will still be unique and will be chronological but won’t necessarily be contiguous.

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

Sidebar

Related Questions

I have this authnav='<li class=last><a href=auth/login>login</a></li>'+ '<li><a href=auth/create_account>create account</a></li>'; It works fine in Firefox,
I have create name range on sheet A so I need to use this
Problem : I have to create a number of tables for caching some amount
I have a library that I created with some business logic that includes writing
Hi I want to create a WCF service that have login method, which is
I'd like to create a subset of Users that don't have a login... basically
I'm creating a login page. I want to create ASP.NET TextBox controls that have
I have created login account on my localhost\sql2008 Server (Eg. User123) Mapped to Database
I have created a user login page and am using Forms Authentication. Users are
I have create my own NSOpenGLView class, right now the data that i want

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.