dbatools is a free PowerShell module with over 200 SQL Server administration, best practice and migration commands included.

Please note that documentation and command names may be out of date while we work furiously towards 1.0


Get-DbaQueryExecutionTime

Displays Stored Procedures and Ad hoc queries with the highest execution times. Works on SQL Server 2008 and above.

Quickly find slow query executions within a database. Results will include stored procedures and individual SQL statements.

Screenshots

Examples

Return the top 100 slowest stored procedures or statements for servers sql2008 and sqlserver2012.

Get-DbaQueryExecutionTime -SqlServer sql2008, sqlserver2012

Return the top 100 slowest stored procedures or statements on server sql2008 for only the TestDB database.

Get-DbaQueryExecutionTime -SqlServer sql2008 -Database TestDB

Return the top 100 slowest stored procedures or statements on server sql2008 for only the TestDB database, limiting results to queries with more than 200 total executions and an execution time over 1000ms or higher.

Get-DbaQueryExecutionTime -SqlServer sql2008 -Database TestDB -MaxResultsPerDb 100 -MinExecs 200 -MinExecMs 1000

Author

This command was created by Brandon Abshire. You can find Brandon blogging at netnerds.net.

Get-Help

From PowerShell, execute Get-Help Get-DbaQueryExecutionTime -Detailed for more information on this function.

Source Code

Want to see the source code? View Get-DbaQueryExecutionTime.ps1 on GitHub
 

Related commands