Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 identity column in sql server

Author  Topic 

sparrow37
Posting Yak Master

148 Posts

Posted - 2010-03-27 : 02:04:42
Hi all,

I have created a table with identity column. When I insert a new value in table, it inserts a new row and next value in identity column. If i delete a row, it adds value next to maximum value and there is always a gap like this in identity column( 1,2,3,4,9,10). Can I set some property in sql server so that if some row is deleted and new row is inserted it should take place of that identity column.

Regards,
Asif Hameed

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-27 : 02:17:20
nope.. there's no direct way to do this unless you write a proc to reclaim lost values. But to be honest you shouldnt be worried at gaps as you can always retrieve records in correct order even with gaps or if you want to generate sequential value, you can do it on the fly using window functions like ROW_NUMBER

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-27 : 13:11:10
Why does it matter if there are gaps?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -