SQL Server Management Studio, how to get execution time down to milliseconds

后端 未结 8 1519
花落未央
花落未央 2020-12-07 07:08

When I submit a batch (e.g., perform a query) in SSMS, I see the time it took to execute in the status bar. Is it possible to configure SSMS to show the query time with mill

相关标签:
8条回答
  • 2020-12-07 07:38

    What you want to do is this:

    set statistics time on
    
    -- your query
    
    set statistics time off
    

    That will have the output looking something like this in your Messages window:

    SQL Server Execution Times: CPU time = 6 ms, elapsed time = 6 ms.

    0 讨论(0)
  • 2020-12-07 07:40

    You can try this code:

    USE AdventureWorks2012;
    GO
    SET STATISTICS TIME ON;
    GO
    SELECT ProductID, StartDate, EndDate, StandardCost 
    FROM Production.ProductCostHistory
    WHERE StandardCost < 500.00;
    GO
    SET STATISTICS TIME OFF;
    GO
    
    0 讨论(0)
  • 2020-12-07 07:45

    To get the execution time as a variable in your proc:

    DECLARE @EndTime datetime
    DECLARE @StartTime datetime 
    SELECT @StartTime=GETDATE() 
    
    -- Write Your Query
    
    
    SELECT @EndTime=GETDATE()
    
    --This will return execution time of your query
    SELECT DATEDIFF(ms,@StartTime,@EndTime) AS [Duration in millisecs] 
    

    AND see this

    Measuring Query Performance : "Execution Plan Query Cost" vs "Time Taken"

    0 讨论(0)
  • 2020-12-07 07:45

    I was after the same thing and stumbled across the following link which was brilliant:

    http://www.sqlserver.info/management-studio/show-query-execution-time/

    It shows three different ways of measuring the performance. All good for their own strengths. The one I opted for was as follows:


    DECLARE @Time1 DATETIME

    DECLARE @Time2 DATETIME

    SET @Time1 = GETDATE()

    -- Insert query here

    SET @Time2 = GETDATE()

    SELECT DATEDIFF(MILLISECOND,@Time1,@Time2) AS Elapsed_MS


    This will show the results from your query followed by the amount of time it took to complete.

    Hope this helps.

    0 讨论(0)
  • 2020-12-07 07:54

    Include Client Statistics by pressing Ctrl+Alt+S. Then you will have all execution information in the statistics tab below.

    0 讨论(0)
  • 2020-12-07 08:01

    Turn on Client Statistics by doing one of the following:

    • Menu: Query > Include client Statistics
    • Toolbar: Click the button (next to Include Actual Execution Time)
    • Keyboard: Shift-Alt-S

    Then you get a new tab which records the timings, IO data and rowcounts etc for (up to) the last 10 exections (plus averages!):

    enter image description here

    0 讨论(0)
提交回复
热议问题