If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > lock table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-15-07, 00:00
ankur02018 ankur02018 is offline
Registered User
 
Join Date: Jun 2007
Posts: 189
Smile lock table

can any tell what is the exact syntax to lock table in a database

[PHP]






ankurkaushik@gmail.com
Reply With Quote
  #2 (permalink)  
Old 06-15-07, 02:52
guyprzytula guyprzytula is offline
Registered User
 
Join Date: Jun 2006
Posts: 471
according the doc :
-LOCK TABLE--+-table-name-+--IN--+-SHARE-----+--MODE---------><
'-nickname---' '-EXCLUSIVE-'
__________________
Best Regards, Guy Przytula
DB2 UDB LUW certified V6/7/8
Reply With Quote
  #3 (permalink)  
Old 06-15-07, 10:00
ankur02018 ankur02018 is offline
Registered User
 
Join Date: Jun 2007
Posts: 189
Smile

thanks for giving me suggestion its working

but after locking table i can select table ,insert data,alter ,delete
so what will be use of locking table??
Reply With Quote
  #4 (permalink)  
Old 06-15-07, 11:33
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by ankur02018
after locking table i can select table ,insert data,alter ,delete
so what will be use of locking table??
That's exactly why you would lock the table: so that *you* can insert, delete, etc. in the table, while *others* cannot interfere.
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #5 (permalink)  
Old 06-15-07, 12:38
ankur02018 ankur02018 is offline
Registered User
 
Join Date: Jun 2007
Posts: 189
Smile

suppose i connect to database as

connect to cricket user ism using ism

then

lock table bcci in share mode

now I can insert , update , delete etc to that table

even other user can also do by connecting that particular database
how can we apply bar to other user on that table by locking
Reply With Quote
  #6 (permalink)  
Old 06-15-07, 13:06
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Locks are released on commit. If you don't switch autocommit off (which I suspect is the case) your lock is released right after the LOCK statement is issued.
Reply With Quote
  #7 (permalink)  
Old 06-15-07, 13:26
ankur02018 ankur02018 is offline
Registered User
 
Join Date: Jun 2007
Posts: 189
Smile

Quote:
Originally Posted by n_i
Locks are released on commit. If you don't switch autocommit off (which I suspect is the case) your lock is released right after the LOCK statement is issued.
no i think this is not the case because autocommint is on
Reply With Quote
  #8 (permalink)  
Old 06-15-07, 15:48
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by ankur02018
no i think this is not the case because autocommint is on
It's really easy to check: just take a locks snapshot after the LOCK statement.
Reply With Quote
  #9 (permalink)  
Old 06-18-07, 01:33
ankur02018 ankur02018 is offline
Registered User
 
Join Date: Jun 2007
Posts: 189
Quote:
Originally Posted by n_i
It's really easy to check: just take a locks snapshot after the LOCK statement.
can you tell in brief how we can check our autocommit status
Reply With Quote
  #10 (permalink)  
Old 06-18-07, 03:01
ankur02018 ankur02018 is offline
Registered User
 
Join Date: Jun 2007
Posts: 189
Smile

Quote:
Originally Posted by ankur02018
can you tell in brief how we can check our autocommit status
yeah I got the command to check your auto commit status


but cant find find whats use of lock tables ?
Attached Thumbnails
lock table-autocommit.jpg  
Reply With Quote
  #11 (permalink)  
Old 06-25-07, 05:58
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
If you acquire a lock in "shared" mode, then other users will be able to access the table and select from it. They won't be able to write to the table.

Different question: why exactly do you want to lock the table? DB2 (or any other decent DBMS) will take care of locking for you and your application should not even worry about it.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #12 (permalink)  
Old 06-28-07, 12:30
ankur02018 ankur02018 is offline
Registered User
 
Join Date: Jun 2007
Posts: 189
Smile

please make me clear why locking tables
Reply With Quote
  #13 (permalink)  
Old 06-29-07, 03:41
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
First, you don't have to lock tables yourself.

Sometimes it may be beneficial to explicitly lock a table to prevent DB2 from acquiring row locks which may later on be escalated to a table lock. But this is something you only do if really necessary.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On