home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!spool.mu.edu!umn.edu!csus.edu!netcom.com!mcentral
- From: mcentral@netcom.com (Media Central)
- Newsgroups: comp.databases.sybase
- Subject: Re: Sequencer or Serial
- Message-ID: <06ynl+l.mcentral@netcom.com>
- Date: 15 Sep 92 00:19:56 GMT
- References: <howard.716498215@judy.cs.iastate.edu> <14821@gazette.bcm.tmc.edu> <howard.716504676@judy.cs.iastate.edu>
- Organization: Netcom - Online Communication Services (408 241-9760 guest)
- Lines: 30
-
- In article <howard.716504676@judy.cs.iastate.edu> howard@cs.iastate.edu (Chris howard) writes:
- >mparsons@fleming.csc.bcm.tmc.edu (Mark Parsons) writes:
- >
- >>Why not set up one table, with one column of type int. Lock
- >>the table when accessing/updating it. The idea is that this
- >>column will hold a counter . . . just increment the column
- >>each time you read the number . .
- >
- >>Mark
- >
- >Well, we thought of that, but we have been unable to determine how to
- >get an exclusive lock on that column between the time that we read
- >the counter, and the time it is updated.
- >
- >The best answer we've come up with is to use a trigger on Update to
- >grab the value after incrementing it. It seems like a hack... at best.
- >
-
- Try this :
- begin tran
- update sequenc set col = col + 1 /* update first and then read */
- select @latest = col from sequenc where 1 = 1
- end tran
-
- By doing an update first within a transaction, you are imposing an
- Exclusive lock on the table(page). This method ensures that each user
- recieves an unique number
-
- cheers,
- shahid ahmed
-