Solved

How to make sure the row in is not locked in WHERE clause?

Posted on 2014-04-08
6
191 Views
Last Modified: 2014-04-09
Here is my query. How do I make sure that row is NOT locked by anyone else? If someone has locked it then it should not return it. It should return me next top ullocked record.

SELECT TOP 1 Id FROM XYZ.
0
Comment
Question by:GouthamAnand
[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
6 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 39986112
Are you talking locked as in DB Lock?

If so then the query will wait until whoever else is done with the table, possibly timing out before the lock is released.

If you're talking about your own Lock column:
select top 1 id from XYZ where lock = 0

What exactly are you trying to do?
0
 
LVL 10

Expert Comment

by:PadawanDBA
ID: 39986142
So I have to ask...  What is the use case for this?  This is a rather in depth request (undocumented traceflag and possibly dmv) and there may be better options.
0
 

Author Comment

by:GouthamAnand
ID: 39986245
I need a TOP 1 record which has not been locked by ANYONE ELSE.

Several users working on the applicaton. And when a user opens a record on UI , it locks the record.

I want to select the top 1 record whish has not been locked by any other user.
0
Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 39986252
I would create your own lockedby column in the application then.

Set the lockedby column when you enter the record to the user
set the lockedby column to null when you leave the record

then you could do
select top 1 id from XYS where lockedby is null
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 39986586
>> when a user opens a record on UI , it locks the record. <<

What UI?  And how specifically does it "lock the record"?

Sorry, but how you're doing this really matters to how to properly answer this q.
0
 

Author Closing Comment

by:GouthamAnand
ID: 39989065
Thanks for all the responses.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 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