1 select --* 2 request_session_id as spid, 3 resource_type as restype, 4 resource_database_id as dbid, 5 DB_NAME(resource_database_id) as dbname, 6 resource_description as res, 7 resource_associated_entity_id as resid, 8 case when resource_type= 'OBJECT' then OBJECT_NAME( resource_associated_entity_id ) 9 end 10 as objectName, 11 request_mode as mode, 12 request_status as status 13 from sys.dm_tran_locks 14 15 16 select --* 17 session_id as spid, 18 connect_time, 19 last_read, 20 last_write, 21 most_recent_sql_handle, 22 text 23 from sys.dm_exec_connections 24 cross apply sys.dm_exec_sql_text(most_recent_sql_handle) --as a 25 where session_id in (56,57) 26 27 select --* 28 session_id as spid, 29 login_time, 30 host_name, 31 program_name, 32 login_name, 33 nt_user_name, 34 last_request_start_time, 35 last_request_end_time 36 from sys.dm_exec_sessions 37 where session_id in (56,57) 38 39 select --* 40 [session_id], 41 [blocking_session_id], 42 [command], 43 [sql_handle], 44 text, 45 [database_id], 46 [wait_type], 47 [wait_time], 48 [wait_resource] 49 from sys.dm_exec_requests 50 cross apply sys.dm_exec_sql_text([sql_handle]) 51 where blocking_session_id>0
ISOLATION LEVEL | note | 读操作 | 写操作 |
READ UNCOMMITTED(with nolock) | 脏读 | 不请求共享锁 | 不妨碍获取排他锁 |
READ COMMITED | 不可重复读 | 读操作不会事务持续期间内保留共享锁, 甚至在语句结束前也不能一直保留共享锁, 这意味着在一个事务处理内部对相同数据资源的两个读操作之间,没有共享锁会锁定该资源 |
因此,其他事务可以在两个读操作 之间更改数据资源, 读操作因而可能每次得到不同的取值 |
REPEATABLE READ(holdlock) | 幻读 | 共享锁一直保持到事务完成为止 | 能阻塞Update,不能阻Insert , 能够防止并发负面影响:丢失更新 |
SERIALIZABLE | 读操作锁定满足查询搜索条件的键的整个范围 | 能阻塞Update,Insert | |
SNAPSHOT | 基于行版本控制(非共享锁) 数据库级别开启 set allow_snapshot_isolation on |
读操作读取的数据行 是事务启动前最后提交的版本 | 进行更新冲突检测 |
READ COMMITTED SNAPSHOT | 基于行版本控制(非共享锁) 数据库级别开启 set read_committed_snapshot_on |
读操作读取的数据行 是语名启动前最后提交的版本 | 不进行更新冲突检测 |