home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / database / sybase / 708 < prev    next >
Encoding:
Text File  |  1993-01-21  |  1.5 KB  |  55 lines

  1. Newsgroups: comp.databases.sybase
  2. Path: sparky!uunet!gatech!destroyer!cs.ubc.ca!newsserver.sfu.ca!sfu.ca!wolfgang
  3. From: wolfgang@fraser.sfu.ca (Wolfgang Richter)
  4. Subject: Locking a table against update
  5. Message-ID: <wolfgang.727637656@sfu.ca>
  6. Keywords: lock
  7. Sender: news@sfu.ca
  8. Organization: Simon Fraser University, Burnaby, B.C., Canada
  9. Date: Thu, 21 Jan 1993 17:34:16 GMT
  10. Lines: 43
  11.  
  12. The following was e-mailed to me and is likely of interest to others.
  13.  
  14. Wolfgang,
  15.  
  16. I thought I would drop you a response to your posting regarding
  17. explicitly locking tables in Sybase.  I have not been following
  18. the news group until recently, so if this information seems new
  19. to you, please feel free to post it:
  20.  
  21. To explicitly lock a table in Sybase, and avoid a deadlock problem:
  22.  
  23.    begin transaction
  24.  
  25.       update <table_name_here> 
  26.       set    <some_column_name> = <some_value> 
  27.       where  0 = 1
  28.       
  29.       /* Table is now exclusivly locked, perform atomic function */
  30.    
  31.    commit transaction
  32.    
  33.  
  34. The trick here is the 'where 0 = 1'.  This will put a lock on the
  35. table (until the commit transaction) without actually changing 
  36. any data in the table (obviously 0 never equals 1).
  37.  
  38. Any other processes will block at the 'update' statement, and will
  39. wait until the 'commit transaction' before proceeding.  No more
  40. deadlocks!
  41.  
  42. Good luck!
  43.  
  44. Paul Tidwell, Software Engineer
  45. Ericsson Network Systems
  46. Richardson, Texas 
  47.  
  48. -- 
  49. -- Wolfgang Richter (e-mail: wolfgang@sfu.ca)
  50. -- Academic Computing Services
  51. -- Simon Fraser University
  52. -- Burnaby, B.C.
  53. -- Canada V5A 1S6
  54. -- Phone: 604-291-4449
  55.