首页 > 数据库技术 > 详细

SQLServer常用语句

时间:2021-08-23 22:56:47      阅读:17      评论:0      收藏:0      [点我收藏+]

查询当前数据库上执行的SQL语句

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



SELECT *
FROM   sys.[sysprocesses] AS syspro
       CROSS apply sys.Dm_exec_sql_text(syspro.sql_handle) AS t
WHERE  status != sleeping
ORDER  BY physical_io DESC; 

 

--查看AlwaysON同步延迟时间
SELECT Datediff(s, last_redone_time, Getdate()) DelayTimeS
FROM   ( ( sys.availability_groups AS ag
           JOIN sys.availability_replicas AS ar
             ON ag.group_id = ar.group_id )
         JOIN sys.dm_hadr_availability_replica_states AS ar_state
           ON ar.replica_id = ar_state.replica_id )
       JOIN sys.dm_hadr_database_replica_states dr_state
         ON ag.group_id = dr_state.group_id
            AND dr_state.replica_id = ar_state.replica_id

 

SQLServer常用语句

原文:https://www.cnblogs.com/ChenRihe/p/15177364.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!