Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Identifier deletion

Status
Not open for further replies.

Shilohcity

Technical User
Jul 12, 2000
136
GB
Hi there

I have a little problem that I am hoping somebody out there can help me with. I have a table with an id column which is set to increment by 1 starting at 1. Each time a record is added it moves to the next number in the sequence but when a record is deleted leaving its id available the next record added still takes the next id in the sequence. What I would like to happen is for any available ids to be used up first e.g.

20 records
record 18 deleted
record added takes id 18 NOT id 21

Does anybody have any suggestions on this?

Thanks
Justin. X-) "Creativity is the ability to introduce order into the randomness of nature." Eric Hoffer

Visit me at
 
The Identity is designed to function as you describe. You could write code to determine where a gap exists, turn identity insert on, force in the identity to fill the gap, and turn identity insert off. The question is, "Why?" Let SQL Server handle the identity values so you don't have to write additional code and worse yet, bog down your server with unnecessary processing.

If you really want to be in control, don't use identity columns. Create a stored procedure (or function in SQL 2000) to determine the next value and use that. You will have to do all the work necessary to insure that multiple users can't use the same value. Terry

The reason why worry kills more people than work is that more people worry than work. - Robert Frost
 
Thanks for your comments I guess either way (server or application processing) Im gonna have to write some code.

Justin. "Creativity is the ability to introduce order into the randomness of nature." Eric Hoffer

Visit me at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top