Solved

Rowlock and primary key

Posted on 2001-07-05
8
504 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
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now