• Srinivas-490730 (11/5/2010)


    Marios.

    Thanks for posting the MP and the relevant scripts.. It helped me a lot.

    I also want to know if we can modify these scripts to alert on long running queries and locking queries.

    If so, what is the SQL script that I have to use?

    Please advise.

    Thanks.

    Srini.

    Sorry for the long delay in responding.

    For SQL scripts that monitor locks, see this excellent link:

    http://www.simple-talk.com/sql/database-administration/investigating-transactions-using-dynamic-management-objects/

    You will need to customize the SCOM objects to reference these scripts accordingly.

    For long-running queries, you may want to use something like this:

    --http://www.sql-server-performance.com/articles/per/tsql_statement_performance_p1.aspx

    SELECT

    creation_time

    ,last_execution_time

    ,total_physical_reads

    ,total_logical_reads

    ,total_logical_writes

    ,execution_count

    ,total_worker_time

    ,total_elapsed_time

    ,total_elapsed_time / execution_count avg_elapsed_time

    ,DatabaseName = DB_NAME(st.dbid)

    ,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) AS statement_text

    ,qp.query_plan

    FROM

    sys.dm_exec_query_stats AS qs

    CROSS APPLY

    sys.dm_exec_sql_text(qs.sql_handle) st

    CROSS APPLY

    sys.dm_exec_query_plan(qs.plan_handle) qp

    ORDER BY

    total_elapsed_time / execution_count DESC;

    __________________________________________________________________________________
    SQL Server 2016 Columnstore Index Enhancements - System Views for Disk-Based Tables[/url]
    Persisting SQL Server Index-Usage Statistics with MERGE[/url]
    Turbocharge Your Database Maintenance With Service Broker: Part 2[/url]