home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.databases.sybase
- Path: sparky!uunet!gatech!destroyer!cs.ubc.ca!newsserver.sfu.ca!sfu.ca!wolfgang
- From: wolfgang@fraser.sfu.ca (Wolfgang Richter)
- Subject: Locking a table against update
- Message-ID: <wolfgang.727637656@sfu.ca>
- Keywords: lock
- Sender: news@sfu.ca
- Organization: Simon Fraser University, Burnaby, B.C., Canada
- Date: Thu, 21 Jan 1993 17:34:16 GMT
- Lines: 43
-
- The following was e-mailed to me and is likely of interest to others.
-
- Wolfgang,
-
- I thought I would drop you a response to your posting regarding
- explicitly locking tables in Sybase. I have not been following
- the news group until recently, so if this information seems new
- to you, please feel free to post it:
-
- To explicitly lock a table in Sybase, and avoid a deadlock problem:
-
- begin transaction
-
- update <table_name_here>
- set <some_column_name> = <some_value>
- where 0 = 1
-
- /* Table is now exclusivly locked, perform atomic function */
-
- commit transaction
-
-
- The trick here is the 'where 0 = 1'. This will put a lock on the
- table (until the commit transaction) without actually changing
- any data in the table (obviously 0 never equals 1).
-
- Any other processes will block at the 'update' statement, and will
- wait until the 'commit transaction' before proceeding. No more
- deadlocks!
-
- Good luck!
-
- Paul Tidwell, Software Engineer
- Ericsson Network Systems
- Richardson, Texas
-
- --
- -- Wolfgang Richter (e-mail: wolfgang@sfu.ca)
- -- Academic Computing Services
- -- Simon Fraser University
- -- Burnaby, B.C.
- -- Canada V5A 1S6
- -- Phone: 604-291-4449
-