Solved

Rowlock and primary key

Posted on 2001-07-05
8
527 Views
Last Modified: 2008-03-17
Is it necessary for a table to have a primary key in order to use Rowlock in a stored procedure that makes changes to one row in the table? If the answer is yes, is it possible for the primary key to be composed.
0
Comment
Question by:aderounm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 18

Expert Comment

by:nigelrivett
ID: 6256050
You don't need a primary key for rowlock - all it does is just locks rows instead of pages.

You could use an identity for a primary key - although you should already have fields that could compose it.
0
 

Author Comment

by:aderounm
ID: 6256734
The problem is that we call the stored procedure from a multiuser environment and we keep getting "deadlock on lock" errors.
0
 
LVL 2

Expert Comment

by:pkohlmil
ID: 6257263
Are you setting LOCK_TIMEOUT to zero? I'm thinking that using a different value on SET LOCK_TIMEOUT might help.
0
Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

 

Accepted Solution

by:
aderounm earned 0 total points
ID: 6257385
It looks like we have solved the problem. We added an index to the table by creating a primary key and everything ran perfectly. No more deadlocks. It seems that you can have a ROWLOCK on any table but it prevents multiuser deadlocks only if used on a table with an index.
0
 
LVL 18

Expert Comment

by:nigelrivett
ID: 6258039
rowlock takes locks on rows only but that doesn't help if you are table scanning as you have to access all pages anyway. Design is the way to avoid deadlocks - i.e. design the processes so that they don't conflict.

pkohlmil
deadlocks are nothing to do with timeouts - quite the reverse.
0
 

Expert Comment

by:CleanupPing
ID: 9282085
aderounm:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question