|
|
sybperl-l Archive
Up Prev Next
From: Michael Peppler <mpeppler at MBAY dot NET>
Subject: Re: next key table
Date: Sep 18 1997 8:58PM
Doug Fairclough wrote:
>
> http://www.sybase.com/products/whitepapers/pkey_wpaper.html
>
> states that :
>
> begin tran
>
> declare @next_key
> update next_key set next_key = next_key + 1
> select @next_key = next_key + 1 from next_key
>
> insert into data_table (key_column, ...) values (@next_key, ...)
>
> commit tran
>
> does anyone know if its necessary to have the 'insert' statement
> _within_ the transaction in order to gaurantee uniqueness in the
> keys generated ?
You should be fine.
In a previous life I had a stored proc that grabbed a key from
the key table, and the key was then used to insert a new row to another
table. I never wrapped the whole thing in a transaction as the only
thing that was important was getting a unique identifier, not
the order in which these identifiers were generated.
Michael
--
Michael Peppler -||- Data Migrations Inc.
mpeppler@datamig.com -||- http://www.mbay.net/~mpeppler
|