|
Posted by newtophp2000 on 06/19/06 20:32
Hello,
Since SQL Server has no sequence generator, I wrote my own. (I claim
no ownership of it as it is closely modeled after earlier discussions
on this topic.) I have included the sql statements below.
While it works independently on its own, It seems to lock in multi-user
environments or in nested-transactions. It s funny really: I have my
main transaction, but the sequence generator below forces another
transaction, which I do not really care for. I cannot remove the extra
transaction from the sequence generator because I would like to discard
any values it retrieved, regardless of whether the main transaction
succeeded or failed.
Any suggestions?
--------------------------------------------------------------------------------
create table my_sequence (name varchar(10), seq int identity (1, 1))
go
declare @next int
begin transaction
update my_sequence set seq = seq + 1 where name = 'abc';
select @next = seq from my_sequence where name = 'abc';
commit transaction
---------------------------------------------------------
Navigation:
[Reply to this message]
|