Path: utzoo!utgpu!news-server.csri.toronto.edu!torsqnt!hybrid!scifi!bywater!uunet!cimshop!davidm From: cimshop!davidm@uunet.UU.NET (David S. Masterson) Newsgroups: comp.databases Subject: Re: Generating unique keys in SYBASE. Whats the best method? Message-ID: Date: 15 Mar 91 19:28:31 GMT References: <1991Mar14.123156.17547@ncs.dnd.ca> Sender: davidm@cimshop.UUCP Organization: Consilium Inc., Mountain View, California Lines: 39 In-reply-to: rpburry@ncs.dnd.ca's message of 14 Mar 91 12:31:56 GMT >>>>> On 14 Mar 91 12:31:56 GMT, rpburry@ncs.dnd.ca (Paul Burry) said: Paul> What is the best mechanism for generating unique keys in SYBASE. Paul> Are there any better (faster, more concurrency) methods than: Paul> begin transaction Paul> /** update (and lock) the key control table **/ Paul> update control_table Paul> set key = key + 1 Paul> where row = 1 Paul> /** grab the key value **/ Paul> select @key=key Paul> from control_table Paul> where row = 1 Paul> commit transaction Paul> /** if the following tranaction is rolled back, then the **/ Paul> /** unique key created will be unused... **/ Paul> begin transaction Paul> /** use the key **/ Paul> insert into the_table Paul> values (@key, ...) Paul> ... Paul> commit transaction I forget how Sybase does this (its been 3 years since I used it), but couldn't the first transaction be made into an insertion trigger that the second transaction will trigger? -- ==================================================================== David Masterson Consilium, Inc. (415) 691-6311 640 Clyde Ct. uunet!cimshop!davidm Mtn. View, CA 94043 ==================================================================== "If someone thinks they know what I said, then I didn't say it!"