Sunday, February 19, 2012

About RowLock

How i have to lock the row while updation of the row while that row is
accessed by various clients and also how i have to release the lockHello -
I would like to provide you couple of reference, hope that helps you.
1. Using Hints in Query
-- This Statement will not produce any locks to the Author Table in Pubs
Database.
Select * from pubs.dbo.authors with (NOLOCK)
Similarly you can use with (ROWLOCK),with (TABLOCK),with(PAGLOCK) in Insert
or Update Statements.
Please check different Isolation Level Mechanism incorporated in SQL Server
Using SP_INDEXOPTION
You can override how SQL Server performs locking on a table by using the
SP_INDEXOPTION command. Below is an example of code you can run to tell SQL
Server to use page locking, not row locks, for a specific table:
SP_INDEXOPTION 'table_name', 'AllowRowLocks', FALSE
GO
SP_INDEXOPTION 'table_name', 'AllowPageLocks', FALSE
GO
Check SP_INDEXOPTION for details in Books On Line in SQL Server.
Thanks
Surajit
"balakarthik" wrote:

> How i have to lock the row while updation of the row while that row is
> accessed by various clients and also how i have to release the lock|||Actually I think the first answer is that you do not have to do anything...
When you update a row, SQL will automatically acquire the locks to protect
the row.
If you are changing a row in a user defined transaction ( Begin tran -
commit) SQL will hold the lock for the duration of the transaction... If you
wish to control locking yourself for some reason, the hints etc is the way..
most of the time I do not use hints - use them only if the standard locking
scheme does not give you the protection you need.
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"balakarthik" <balakarthik@.discussions.microsoft.com> wrote in message
news:458E7B1F-D387-4771-B844-02B4B8EDC4E0@.microsoft.com...
> How i have to lock the row while updation of the row while that row is
> accessed by various clients and also how i have to release the lock

No comments:

Post a Comment