Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How can I auto-increment a column without using IDENTITY property?

I have created a table with IDENTITY column. But i am facing identity value jump issue. I want to create auto-increment column without using IDENTITY property.

Is it useful to use NEWID function?
Posted
Updated 10-Sep-15 20:36pm
v3
Comments
phil.o 11-Sep-15 3:21am    
value jump issue
Why do you care about actual primary key values? These jump issues, will they prevent your database from working? I never take care about primary key values; I even rarely display them, as they only have a meaning from the database point of view, not the user's one.
Schatak 11-Sep-15 3:59am    
If its an Identity column and auto increment , i do not thing Jump issue will be there until you delete some records.
[no name] 11-Sep-15 4:02am    
i never delete records.automatically jump auto increment Number.
jaket-cp 11-Sep-15 7:50am    
Just to clarify, are you using "SQL-server-2008R2" and not "SQL Server 2012".
The only reason I ask is that the identity re-seed (jump issue) is a built in feature to "SQL Server 2012".
If you are on "SQL Server 2012", then check out this link:
http://www.codeproject.com/Tips/668042/SQL-Server-Auto-Identity-Column-Value-Jump-Is

NEWID - Creates a unique value of type uniqueidentifier. If you want unique value then can use it but it is not auto incremented.

You can use another concept in SQL SERVER. That is Sequence.

Create Sequence in SQL Server and use that Sequence in your table column.

https://www.simple-talk.com/sql/learn-sql-server/sql-server-sequence-basics/[^]
 
Share this answer
 
Comments
[no name] 11-Sep-15 7:27am    
From my Point of view, sequence is the best choice. But OP mentioned MSSQL2008 and what I know it is not available there. Anyway a 5.
I agree with ManasKumarM.
But I think that if you have a "jump" issue with identity, probably You will have with sequence too.
I suppose you have something in your code or in your flow that reserves the next identity and does not use it. Like a "rollback" or a "cancel" request.
May be?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900