• SQLServer常用语句


    查询当前数据库上执行的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
  • 相关阅读:
    Win10
    编码
    [转帖] Tomcat安全配置小技巧
    关于redis bind
    query data filtered by a JSON Column in SQLAlchemy
    Flask多线程环境下logging
    Flask request
    [转] MySQL树结构递归查询处理
    [转]了解BFF架构
    转载:ELK实战系列3-RabbitMQ+ELK搭建日志平台
  • 原文地址:https://www.cnblogs.com/ChenRihe/p/15177364.html
Copyright © 2020-2023  润新知