Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Table Lock

Author  Topic 

rakesh_09
Starting Member

8 Posts

Posted - 2008-06-25 : 06:41:30
Hi,

Can someone tell how to lock a particluar table in SQL Server 2005? Also how do I unlock the table????

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-25 : 06:47:15
Locks are automatically placed by server based on action you perform on it and also transaction isolation set.
DO you mean denying permission on table for some users?
Go to Top of Page

rakesh_09
Starting Member

8 Posts

Posted - 2008-06-25 : 07:15:33
yes... absolutely
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-25 : 07:48:42
quote:
Originally posted by rakesh_09

yes... absolutely


look for GRANT & DENY statement in sql server books online
Go to Top of Page

rakesh_09
Starting Member

8 Posts

Posted - 2008-06-25 : 07:55:41
how do i lock a table in EXCLUSIVE mode manually??? i mean by using sql statements
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-25 : 08:01:02
quote:
Originally posted by rakesh_09

how do i lock a table in EXCLUSIVE mode manually??? i mean by using sql statements


you can use XLOCK. see this:-

http://www.tar.hu/sqlbible/sqlbible0057.html
Go to Top of Page

rakesh_09
Starting Member

8 Posts

Posted - 2008-06-26 : 02:18:31
i have two users user1 and user2...

i execute the below sql statement using user1

BEGIN TRANSACTION
select * from user_tbl with (XLOCK)

so will the user_tbl locked for user2 until user1 gives a COMMIT statement?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-26 : 02:47:50
quote:
Originally posted by rakesh_09

i have two users user1 and user2...

i execute the below sql statement using user1

BEGIN TRANSACTION
select * from user_tbl with (XLOCK)

so will the user_tbl locked for user2 until user1 gives a COMMIT statement?



yup. it will be locked until end of transaction.
Go to Top of Page

rakesh_09
Starting Member

8 Posts

Posted - 2008-06-26 : 03:00:23
thanks...

but still the SELECT query works on the table... is there any lock that does not even allow the SELECT query to be executed???

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-26 : 03:28:07
quote:
Originally posted by rakesh_09

thanks...

but still the SELECT query works on the table... is there any lock that does not even allow the SELECT query to be executed???




SELECT query? which select query? you mean for second user?
Go to Top of Page

rakesh_09
Starting Member

8 Posts

Posted - 2008-06-26 : 04:03:19
yes..... if the second user is able to execute a SELECT query on the lock table..... is there any type of lock which does not even allow to execute the SELECT query?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-26 : 04:13:22
quote:
Originally posted by rakesh_09

yes..... if the second user is able to execute a SELECT query on the lock table..... is there any type of lock which does not even allow to execute the SELECT query?


you mean second user is able to view select query results while first user hasnt comited/rollbacked his transaction?
Go to Top of Page

rakesh_09
Starting Member

8 Posts

Posted - 2008-06-26 : 04:19:00
yes... first user has locked the table and has not committed the transaction... but the second user can see the select query results.... is there any lock that an be applied on the table so that the second user is no able to execute the select query also???
Go to Top of Page
   

- Advertisement -