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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to re arrange identity column's value

Author  Topic 

ryanlcs
Yak Posting Veteran

62 Posts

Posted - 2010-10-03 : 04:24:25
Hi

I have a identity column where the values will become disorder, such as
1,3,4,5,6,7,10,15

How can I rearrange/reset the values so that it will be in "nice order" of 1,2,3,4,5,6,7,8

Thanks.

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-10-03 : 05:00:18
Is the identity column a primary key ?
If not then you can drop the column and again add the column as identity column.

But remember to consider the following
Type of environment : Production or development
No of rows in table

There are other ways too achieve the requirement. If you can provide more detailed info then we can suggest you better method.
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2010-10-03 : 06:53:26
Or how about adding ORDER BY $identity to your queries? Ordering data is a presentation issue, it has no bearing on how the data is stored or queried.
Go to Top of Page
   

- Advertisement -