zoukankan      html  css  js  c++  java
  • 常用命令

    -----查看sql 读取IO

    SELECT
    SPID = er.session_id
    ,Status = ses.status
    ,[Login] = ses.login_name
    ,Host = ses.host_name
    ,BlkBy = er.blocking_session_id
    ,DBName = DB_Name(er.database_id)
    ,CommandType = er.command
    ,SQLStatement = st.text
    ,ObjectName = OBJECT_NAME(st.objectid)
    ,ElapsedMS = er.total_elapsed_time
    ,CPUTime = er.cpu_time
    ,IOReads = er.logical_reads + er.reads
    ,IOWrites = er.writes
    ,LastWaitType = er.last_wait_type
    ,StartTime = er.start_time
    ,Protocol = con.net_transport
    ,ConnectionWrites = con.num_writes
    ,ConnectionReads = con.num_reads
    ,ClientAddress = con.client_net_address
    ,Authentication = con.auth_scheme
    FROM sys.dm_exec_requests er
    OUTER APPLY sys.dm_exec_sql_text(er.sql_handle) st
    LEFT JOIN sys.dm_exec_sessions ses
    ON ses.session_id = er.session_id
    LEFT JOIN sys.dm_exec_connections con
    ON con.session_id = ses.session_id
    WHERE er.session_id > 50
    --AND @SessionID IS NULL OR er.session_id = @SessionID
    ORDER BY
    er.blocking_session_id DESC
    ,er.session_id

    ----查询阻塞的sql 语句

    SELECT * FROM master.sys.sysprocesses WHERE blocked<>0

    WITH temp ( BSID, SID, sql_handle )
    AS ( SELECT blocking_session_id ,
    session_id ,
    sql_handle
    FROM sys.dm_exec_requests
    WHERE blocking_session_id <> 0
    UNION ALL
    SELECT A.blocking_session_id ,
    A.session_id ,
    A.sql_handle
    FROM sys.dm_exec_requests A
    JOIN temp B ON A.SESSION_ID = B.BSID
    )
    SELECT C.BSID ,
    C.SID ,
    S.login_name ,
    S.host_name ,
    S.status ,
    S.cpu_time ,
    S.memory_usage ,
    S.last_request_start_time ,
    S.last_request_end_time ,
    S.logical_reads ,
    S.row_count ,
    q.text
    FROM temp C
    JOIN sys.dm_exec_sessions S ON C.sid = s.session_id
    CROSS APPLY sys.dm_exec_sql_text(C.sql_handle) Q
    ORDER BY sid

  • 相关阅读:
    leetcode5 Longest Palindromic Substring
    leetcode17 Letter Combinations of a Phone Number
    leetcode13 Roman to Integer
    leetcode14 Longest Common Prefix
    leetcode20 Valid Parentheses
    leetcode392 Is Subsequence
    leetcode121 Best Time to Buy and Sell Stock
    leetcode198 House Robber
    leetcode746 Min Cost Climbing Stairs
    tomcat下使用druid配置jnid数据源
  • 原文地址:https://www.cnblogs.com/jobnet/p/7105036.html
Copyright © 2011-2022 走看看