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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:07:57+00:00 2026-05-14T22:07:57+00:00

Scenario: I have a fairly generic table (Data), that has an identity column. The

  • 0

Scenario: I have a fairly generic table (Data), that has an identity column. The data in this table is grouped (lets say by city).

The users need an identifier in order for printing on paper forms, etc.
The users can only access their cites data, so if they use the identity column for this purpose they will see odd numbers (e.g. a ‘New York’ user might see 1,37,2028… as the listed keys.

Idealy they would see 1,2,3… (or something similar)

The problem of course is concurrency, this being a web application you can’t just have something like:
UserId = Select Count(*)+1 from Data Where City=’New York’

Has anyone come up with any cunning ways around this problem?

Updated – from the comments below I think I want something like the SP below. Not entirely sure how the recursion should work in the CATCH block.

ALTER PROCEDURE [dbo].[DataContainer_Insert] 
@SomeData varchar(max),
@DataContainerId int out    
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    BEGIN TRY
        SELECT @UserId = MAX(UserId) From DataContainer
        INSERT INTO DataContainer (UserId, SomeData)
        VALUES (@UserId, SomeData)

        SELECT @DataContainerId = scope_identity()
    END TRY
    BEGIN CATCH
        --try again
        exec DataContainer_Insert @DataContainerId, @SomeData
    END CATCH       

END
  • 1 1 Answer
  • 1 View
  • 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-14T22:07:57+00:00Added an answer on May 14, 2026 at 10:07 pm

    Well, you could use your UserId = Select Count(*)+1 from Data Where City='New York' idea if you add a spanning uniqueness constraint on city and UserId (to guarantee that there would only ever be 1 instance of a particular Id and City). Then you just need to be able to handle the constraint violations (by resubmitting).

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

Sidebar

Related Questions

Scenario: I have a text file that has pipe (as in the | character)
I'm facing a really strange problem that has me smoked. I have a fairly
I have a fairly straight-forward scenario that I am trying to solve but I'm
I have a following fairly simple scenario: Some data needs to be written into
I have what appears to be a fairly common scenario: I have a database
Scenario: You have an ASP.Net webpage that should display the next image in a
Scenario: I have a document I created using LaTeX (my resume in this case),
The scenario: we have a web system that automatically generates office 2003 excel files
Here's my scenario - I have an SSIS job that depends on another prior
Here's the scenario: You have a Windows server that users remotely connect to via

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.