--查询死锁和阻塞的sql语句
while 1>0
begin
insert into tb(sqlt,ios)
select SUBSTRING(st.text, (qs.statement_start_offset/2) + 1,
((CASE statement_end_offset
WHEN -1 THEN DATALENGTH(st.text)
ELSE qs.statement_end_offset END
- qs.statement_start_offset)/2) + 1),a.physical_io from master..sysprocesses a
cross apply sys.dm_exec_sql_text(a.sql_handle) b
where (b.text like '%select%' or b.text like '%insert%'
or b.text like '%update%' or
b.text like '%delete%') and a.blocked=0 and b.text not like '%master..sysprocesses%'
and b.text not like '%SERVERPROPERTY%'
end
CREATE TABLE [dbo].[tb](
[id] [int] IDENTITY(1,1) NOT NULL,
[sqlT] [varchar](8000) NULL,
[sdate] [datetime] NULL,
[ios] [int] NULL
) ON [PRIMARY]
select * from tb order by ios desc where sqlt like '%update workflowstep set isfinished=1%'