April 19, 2006 at 5:08 pm
declare @OrderID int
@OrderID = OrderID--, -- I'm just getting an OrderID by using the ProductID ... I know there may be many Orders... but I only want one
FROM
dbo.[Order Details]
WHERE
ProductID = @ProductID
--WITH (UPDLOCK)
--WITH (ROWLOCK)
SET
OrderDate = GETDATE()
WHERE OrderID = @OrderID -- this will match exactly one record .. here and in my code
begin
ROLLBACK TRAN -- after checking the locks with the other query... run this standalone to clear it out
end
---------------- end script 1
----------------- script 2
-- you have to change the value to your ID of your Northwind database ... this is some code I found on the internet, but sp_lock (and the code I found for sp_lock2) show similar
declare @DataBaseID varchar (5)
set @DataBaseID = 8
/* put here your number (get it from sp_helpdb)*/
select
substring (v.name, 1, 4) As Type,
object_name(rsc_objid)as ObJName,
convert (smallint,req_spid) As spid,
rsc_dbid As dbid,
rsc_objid As ObjId,
object_name(rsc_objid)as ObJName,
rsc_indid As IndId,
substring (v.name, 1, 4) As Type,
substring (rsc_text, 1, 16) as Resource,
substring (u.name, 1, 8) As Mode,
substring (x.name, 1, 5) As Status
from master.dbo.syslockinfo,
master.dbo.spt_values v,
master.dbo.spt_values x,
master.dbo.spt_values u
-- master.dbo.sysdatabases DB
where master.dbo.syslockinfo.rsc_type = v.number
and v.type = 'LR'
and master.dbo.syslockinfo.req_status = x.number
and x.type = 'LS'
and master.dbo.syslockinfo.req_mode + 1 = u.number
and u.type = 'L'
and rsc_objid <> 0
and rsc_dbid = @DataBaseID
order by v.name--spid
-- end script 2
-- I posted this on the sql.programming microsoft newsgroup also.
April 20, 2006 at 12:35 am
What type is the TAB lock? S, X, IX, Sch-S?
An IX lock on table level is fairly normal when doing modifications. It's not a full exclusive lock, it's there in case SQL has to escalate the page/row locks to table. Usually if there's an X row lock there will be a IX page/extent lock and if there's an X page/extent lock then there will be a IX table lock
From Books Online:
As the Microsoft SQL Server Database Engine acquires low-level locks, it also places intent locks on the objects containing the lower-level objects:
An UPDATE statement acquires these locks:
An intent exclusive (IX) lock is compatible with an IX lock mode because IX means the intention is to update only some of the rows rather than all of them. Other transactions that attempt to read or update some of the rows are also permitted as long as they are not the same rows being updated by other transactions.
--
It would be helpful if you could post the structure of your table, including indexes and the query and what locks you see.
Check the execution plan, make sure that the optimiser isn't suggesting a table scan. Check and make sure your indexes aren't too fragmented.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply