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 2000 Forums
 SQL Server Development (2000)
 Reuse Indentity Value

Author  Topic 

ddasilva99
Starting Member

26 Posts

Posted - 2006-10-25 : 10:16:56
Is there a way to reuse the identity value?

Example, if I add a row - the system auto generates a ID of "5". If I delete the row and readd a new row- the system generates ID of "6".

How do I get it to regenerate an ID of "5"?

Thanks,
Derek

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2006-10-25 : 10:46:04
You should NOT worry about having sequential ID numbers. The ID number means something to SQL SERVER, you should not be caring about it.

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

ddasilva99
Starting Member

26 Posts

Posted - 2006-10-25 : 10:53:40
Don- thank you for your note.
I want to use the ID as a "student id" I would prefer that the ID was sequential so that there arent gaps in the "student id"

Any suggestions?
Thanks,
D
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2006-10-25 : 11:16:16
Use dbcc checkident to reseed the identity. It is not a best practice to add business value to a surrogate key ...

Jay White
Go to Top of Page

ddasilva99
Starting Member

26 Posts

Posted - 2006-10-25 : 11:35:57
good to know- thank you
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-10-25 : 12:14:40
Don't use an identity column

http://weblogs.sqlteam.com/brettk/archive/2004/06/29/1687.aspx



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

ddasilva99
Starting Member

26 Posts

Posted - 2006-10-25 : 13:11:28
Brett- thank you for your link.

Why is it bad to use the Identity value as a 'business value'?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-10-25 : 13:16:29
As stated before a surrogate key (Identity) should not have any meaning other than to identify the row to access the data or to join to other tables.

You are placing a business reason to the id, and as you found out, this could get sticky, more so than just worrying about gaps. What you should do is keep the identity, and create another column for the "ID"



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

ddasilva99
Starting Member

26 Posts

Posted - 2006-10-25 : 13:30:49
Awesome feedback- thank you
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-10-28 : 02:59:36
Even if you do that you will "lose" ID numbers if the transaction is rolled back.

But then the other good folk here already said "don't use IDENTITY if you want contiguous numbers"

Kristen
Go to Top of Page
   

- Advertisement -