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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:01:57+00:00 2026-05-16T14:01:57+00:00

I have various reasons for needing to implement, in addition to the identity column

  • 0

I have various reasons for needing to implement, in addition to the identity column PK, a second, concurrency safe, auto-incrementing column in a SQL Server 2005 database. Being able to have more than one identity column would be ideal, but I’m looking at using a trigger to simulate this as close as possible to the metal.

I believe I have to use a serializable isolation level transaction in the trigger. Do I go about this like Ii would use such a transaction in a normal SQL query?

It is a non-negotiable requirement that the business meaning of the second incrementing column remain separated from the behind the scenes meaning of the first, PK, incrementing column.

To put things as simply as I can, if I create JobCards ‘0001’, ‘0002’, and ‘0003’, then delete JobCards ‘0002’ and ‘0003’, the next Jobcard I create must have ID ‘0002’, not ‘0004’.

  • 1 1 Answer
  • 3 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-16T14:01:58+00:00Added an answer on May 16, 2026 at 2:01 pm

    This is probably a terrible idea, but it works in at least a limited use scenario

    Just use a regular identity and reseed on deletes.

    create table reseedtest (
       a int identity(1,1) not null,
       name varchar(100)
    )
    
    insert reseedtest values('erik'),('john'),('selina')
    select * from reseedtest
    
    go
    CREATE TRIGGER TR_reseedtest_D ON reseedtest FOR DELETE
    AS
    BEGIN TRAN
    DECLARE @a int
    SET @a = (SELECT TOP 1 a FROM reseedtest WITH (TABLOCKX, HOLDLOCK))
    --anyone know another way to lock a table besides doing something to it?
    DBCC CHECKIDENT(reseedtest, reseed, 0)
    DBCC CHECKIDENT(reseedtest, reseed)
    COMMIT TRAN
    GO
    
    delete reseedtest where a >= 2
    insert reseedtest values('katarina'),('david')
    select * from reseedtest
    
    drop table reseedtest
    

    This won’t work if you are deleting from the “middle of the stack” as it were, but it works fine for deletes from the incrementing end.

    Reseeding once to 0 then again is just a trick to avoid having to calculate the correct reseed value.

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

Sidebar

Related Questions

We have a slightly unreliable database server, for various reasons, and as a consequence
I have created my own Tree implementation for various reasons and have come up
Unfortunately it looks like for various reasons I'm going to have to use Visual
I have a particular PHP page that, for various reasons, needs to save ~200
I have a form which has a lot of SELECTs. For various reasons, I'd
I am running into this massive problem, I have to for various reasons change
For various reasons I have clean installed my dev box and it is running
I have an asynchronous operation that for various reasons needs to be triggered using
For various reasons, I have the entry in my .gitignore in the root of
I have a large application written in C++, For various reasons I am going

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.