-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLockingDemo.sql
More file actions
69 lines (51 loc) · 1.22 KB
/
LockingDemo.sql
File metadata and controls
69 lines (51 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
USE tempdb ;
GO
--create a table for the demo
CREATE TABLE demo
(
column1 INT NOT NULL
IDENTITY
,column2 VARCHAR(10)
) ;
--start a transaction
BEGIN TRANSACTION ;
--insert a row into the transaction
INSERT
demo ( column2 )
VALUES ( 'something' ) ;
USE tempdb ;
GO
--what's the dbid for tempdb?
DECLARE @dbid INT ;
SET @dbid = DB_ID() ;
--what's objectid for our demo table?
DECLARE @objectid INT ;
SET @objectid = OBJECT_ID(N'tempdb.dbo.demo') ;
--look at locking in the tempdb
SELECT
resource_type
,resource_database_id
,resource_associated_entity_id
,request_mode
,request_type
,request_session_id
FROM
sys.dm_tran_locks
WHERE
resource_database_id = @dbid ;
--limit the results to only the demo table
SELECT
*
FROM
sys.dm_tran_locks
WHERE
resource_database_id = @dbid AND
resource_associated_entity_id = @objectid ;
select * from sys.dm_tran_locks
commit transaction
sp_who2
sp_lock
kill 76
select * from sys.dm_os_wait_stats
select * from sys.dm_os_wait_stats
select * from sys.dm_tran_locks