Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i have record like this

sno    name        mail
1       vijay     vijay@email.com
2       ajith     ajith@email.com
3       vivek     vivek@email.com


in sno i have applied identity so it will increment by 1 automatically

my question is now i delete 2 record means the output is
sno    name        mail
1       vijay     vijay@email.com
3       vivek     vivek@email.com


but i need the output like this
sno    name        mail
1       vijay     vijay@email.com
2       vivek     vivek@email.com

the 3 rd record identity field need to change as 2
Posted
Updated 1-Nov-12 23:10pm
v2

Hi Friend,

Please see below link....!!!
I am sure it will helpful to you.
http://www.simple-talk.com/sql/t-sql-programming/identity-columns/[^]

Regards,
Prasad
 
Share this answer
 
First I have a question. Why do you need to update the identity columns. Identity columns are maintained by SQL Server itself. If you need a report like showing the records in srno without breaking the sequence, you can try below code.

SQL
Select Row_Number() over ( order by SrNo) as SrNo,Name,Mail from yourTableName
 
Share this answer
 
 
Share this answer
 
This is by design, IDENTITY columns are maintained by the system and the value does not change when you delete records, this is to maintain referential integrity elsewhere.

If you need incrementing values without holes try adding your own column and maintaining the values your self.
 
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