Locks: Difference between revisions
From Sage CRM Knowledge Base
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 31: | Line 31: | ||
---- | ---- | ||
UPDATE | |||
Communication | |||
SET | |||
Comm_DateTime = ctor_bookingdatetime | |||
FROM | |||
Communication | |||
INNER JOIN | |||
ctOrders | |||
ON | |||
) | ctor_ctOrdersID=comm_ctorderid | ||
and ctor_case_caseid is null and ctor_engineeruserid is not null and ctor_orderStage in ('confirmed','booked','jobdone') and DATEDIFF(day,ctor_bookingdatetime,Comm_DateTime)<>0 | |||
Latest revision as of 21:48, 30 May 2014
SQL for detecting locks in SQL
SELECT L.request_session_id AS SPID,
DB_NAME(L.resource_database_id) AS DatabaseName,
O.Name AS LockedObjectName,
P.object_id AS LockedObjectId,
L.resource_type AS LockedResource,
L.request_mode AS LockType,
ST.text AS SqlStatementText,
ES.login_name AS LoginName,
ES.host_name AS HostName,
TST.is_user_transaction as IsUserTransaction,
AT.name as TransactionName,
CN.auth_scheme as AuthenticationMethod
FROM sys.dm_tran_locks L
JOIN sys.partitions P ON P.hobt_id = L.resource_associated_entity_id
JOIN sys.objects O ON O.object_id = P.object_id
JOIN sys.dm_exec_sessions ES ON ES.session_id = L.request_session_id
JOIN sys.dm_tran_session_transactions TST ON ES.session_id = TST.session_id
JOIN sys.dm_tran_active_transactions AT ON TST.transaction_id = AT.transaction_id
JOIN sys.dm_exec_connections CN ON CN.session_id = ES.session_id
CROSS APPLY sys.dm_exec_sql_text(CN.most_recent_sql_handle) AS ST
WHERE resource_database_id = db_id()
ORDER BY L.request_session_id
UPDATE
Communication
SET
Comm_DateTime = ctor_bookingdatetime
FROM
Communication
INNER JOIN
ctOrders
ON
ctor_ctOrdersID=comm_ctorderid
and ctor_case_caseid is null and ctor_engineeruserid is not null and ctor_orderStage in ('confirmed','booked','jobdone') and DATEDIFF(day,ctor_bookingdatetime,Comm_DateTime)<>0