SQL SERVER优化查询速度---建立表索引

1.获取SQL SERVER 正在执行的语句信息---在master数据库执行以下语句:

SELECT  
  [session_id],
  [blocking_session_id] AS '正在阻塞其他会话的会话ID',
  DB_NAME([database_id]) AS '数据库名称',
  [request_id],
  [cpu_time],
  [start_time] AS '开始时间',
  [status] AS '状态',
  [command] AS '命令',
  dest.[text] AS 'sql语句',
  [reads] AS '物理读次数',
  [writes] AS '写次数',
  [logical_reads] AS '逻辑读次数',
  [row_count] AS '返回结果行数',
  [wait_type] AS '等待资源类型',
  [wait_time] AS '等待时间',
  [wait_resource] AS '等待的资源'
  FROM sys.[dm_exec_requests] AS der
  CROSS APPLY
  sys.[dm_exec_sql_text](der.[sql_handle]) AS dest
  WHERE 1=1
   ORDER BY [session_id] DESC

2.杀死指定的阻塞语句

 

 

 

3.优化查询速度--简历表索引

CREATE NONCLUSTERED INDEX [PK_INDEX_WORKAPPLYEXT_ENTITY_ID]
ON [dbo].[WORK_APPLY_EXT] ([ST_ENTITY_ID])

你可能感兴趣的:(SQL SERVER优化查询速度---建立表索引)