Home > Archive > Microsoft SQL Server forum > July 2005 > Unique number/sequence









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Unique number/sequence
pluton

2005-07-04, 3:23 am

Hallo,

Hot to get unique, sequential number during execution
of stored procedure ?

I can create table with autoincrement column,
add record, get ident_current and delete record
each time i need the number.
However its not elegant i guess.


best regards
pluton



Simon Hayes

2005-07-04, 7:23 am

See this thread for an example of using IDENTITY as a sequence
generator:

http://groups-beta.google.com/group...d1a492
4c


But remember that IDENTITY by itself is not guaranteed to be sequential
- if you really need sequential values with no gaps, then you'll have
to write your own code to do that. Requiring sequential numbers is
rather unusual, and could create performance problems - if you DELETE a
single row, you may have to UPDATE a large number of other rows to
maintain the sequence.

If this isn't helpful, you might want to give some more details of
exaclty what you need, especially why you need sequential numbers, and
what you want to happen when a row is DELETEd from the table.

Simon

pluton

2005-07-04, 7:23 am

> See this thread for an example of using IDENTITY as a sequence
> generator:


Thanks a lot.

> - if you really need sequential values with no gaps,


Gaps are accepted :)

> If this isn't helpful


It is :) thanks :)

> what you want to happen when a row is DELETEd from the table.


Just save space :)

Regards
pluton


--CELKO--

2005-07-04, 8:23 pm

>> I can create table with autoincrement column [sic], add record [sic] , get ident_current and delete record [sic] each time i need the number. However its not elegant i guess.<<

Rows are not records -- totally different concepts that separate an
RDBMS from file systems.

In RDBMS, there are sets and not sequences -- think sets and not
magnetic tapes. A key is a subset of attributes that make a row (not
a record!!) unique. The internal state of a counter when something was
inserted into PHYSICAL storage is not part of a LOGICAL data model.

The idea of a key is not that a machine invents them on the fly based
on the internal state of hardware; the idea is that they are a part of
the reality which you are modeling.

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2009 droptable.com