Home All Groups Group Topic Archive Search About

How to program around row locks

Author
24 Aug 2006 1:12 PM
Rob
How would you write a stored procedure to look at possible row locks prior
to execution ?

For example,  we will be periodically executing a command that updates a
column in every row of a table.  If  any users are editing the table, we
would have a potential timeout situation.   How can you test for this
within a stored proc ?

Author
24 Aug 2006 1:26 PM
Tracy McKibben
Rob wrote:
> How would you write a stored procedure to look at possible row locks prior
> to execution ?
>
> For example,  we will be periodically executing a command that updates a
> column in every row of a table.  If  any users are editing the table, we
> would have a potential timeout situation.   How can you test for this
> within a stored proc ?
>
>
>

You typically don't "test" for row locking, you just let SQL deal with
it.  This column that you're updating, can you provide more info?  You
might benefit from moving this column into a seperate table, depending
on how the column is used.


--
Tracy McKibben
MCDBA
http://www.realsqlguy.com
Author
24 Aug 2006 4:20 PM
Rob
Thanks Tracy,

These columns are in a table used by an ERP system (cannot move the column
or ERP would crash).   The ERP system appears to lock the tables during
certain processes which result in a time out error while attempting to run
an update.   So I wanted to test for the condition, and not run the update
if the table was in use.



Show quote
"Tracy McKibben" <tr***@realsqlguy.com> wrote in message
news:44EDA8F9.80209@realsqlguy.com...
> Rob wrote:
>> How would you write a stored procedure to look at possible row locks
>> prior to execution ?
>>
>> For example,  we will be periodically executing a command that updates a
>> column in every row of a table.  If  any users are editing the table, we
>> would have a potential timeout situation.   How can you test for this
>> within a stored proc ?
>>
>>
>>
>
> You typically don't "test" for row locking, you just let SQL deal with it.
> This column that you're updating, can you provide more info?  You might
> benefit from moving this column into a seperate table, depending on how
> the column is used.
>
>
> --
> Tracy McKibben
> MCDBA
> http://www.realsqlguy.com
Author
24 Aug 2006 5:05 PM
Tracy McKibben
Rob wrote:
> Thanks Tracy,
>
> These columns are in a table used by an ERP system (cannot move the column
> or ERP would crash).   The ERP system appears to lock the tables during
> certain processes which result in a time out error while attempting to run
> an update.   So I wanted to test for the condition, and not run the update
> if the table was in use.
>

I doubt the ERP system is explicitly locking tables, it's probably
locking pages or rows (normal behavior) within the table.  Multiply that
by X users, and you have multiple locks scattered throughout a table.
Then along comes your update, that you said is updating every row.  That
update will likely get escalated (again, normal behavior) to a table
lock, but since there are other locks already in place, it has to wait
for those to be released.

How are you issuing this update command?  You shouldn't see a "timeout
error" in Query Analyzer, it will just sit there and spin until the
locks are released.


--
Tracy McKibben
MCDBA
http://www.realsqlguy.com
Author
25 Aug 2006 9:28 AM
Rob
Actually, I was using Access as a client tool (so Access caused the
time-out).   Are you saying that if I run a stored proc it should work ok ?
I do not want the ERP to get "held up" in any way due to this process... so,
if the sp does not execute successfully within a certain time period, I
would like to stop the process.

Thanks,
Rob



Show quote
"Tracy McKibben" <tr***@realsqlguy.com> wrote in message
news:44EDDC5C.3060502@realsqlguy.com...
> Rob wrote:
>> Thanks Tracy,
>>
>> These columns are in a table used by an ERP system (cannot move the
>> column or ERP would crash).   The ERP system appears to lock the tables
>> during certain processes which result in a time out error while
>> attempting to run an update.   So I wanted to test for the condition, and
>> not run the update if the table was in use.
>>
>
> I doubt the ERP system is explicitly locking tables, it's probably locking
> pages or rows (normal behavior) within the table.  Multiply that by X
> users, and you have multiple locks scattered throughout a table. Then
> along comes your update, that you said is updating every row.  That update
> will likely get escalated (again, normal behavior) to a table lock, but
> since there are other locks already in place, it has to wait for those to
> be released.
>
> How are you issuing this update command?  You shouldn't see a "timeout
> error" in Query Analyzer, it will just sit there and spin until the locks
> are released.
>
>
> --
> Tracy McKibben
> MCDBA
> http://www.realsqlguy.com
Author
28 Aug 2006 1:35 PM
Tracy McKibben
Rob wrote:
> Actually, I was using Access as a client tool (so Access caused the
> time-out).   Are you saying that if I run a stored proc it should work ok ?
> I do not want the ERP to get "held up" in any way due to this process... so,
> if the sp does not execute successfully within a certain time period, I
> would like to stop the process.
>
> Thanks,
> Rob
>

Sorry for the delay, I took a long weekend...  I'm not saying
definitively that moving your update to a stored proc will "just work",
but it will be more likely to.  I would encourage you to give it a try,
and then post back here if you need more help.  It will be easier to
diagnose as a stored proc.


--
Tracy McKibben
MCDBA
http://www.realsqlguy.com

AddThis Social Bookmark Button