home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / database / sybase / 6 < prev    next >
Encoding:
Internet Message Format  |  1992-09-14  |  1.5 KB

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