Calculate query execution time

Posted on 2012-08-20
Last Modified: 2012-08-29
I would like rebuild few fragmented indexes. So, I will be executing the REBUILD query one after other. But I would like to make a note of the time taken for rebuild operation to complete for each index. Is there any easy way to do that???

Otherwise I include a 'select CURRENT_TIMESTAMP' before and after my rebuild query.

Please reply with any tips, scripts. Thanks!
Question by:w3brang3r
    LVL 68

    Expert Comment

    It's probably best to capture time before and after the rebuild command.

    You can set SET STATISTICS TIME ON, to have SQL echo the time, but in cases that itself has been shown to degrade performance, so, as above, I suggest just capturing the time yourself before and after.
    LVL 75

    Expert Comment

    by:Anthony Perkins
    But I would like to make a note of the time taken for rebuild operation to complete for each
    index. Is there any easy way to do that???

    If you use the script here, it will not only reindex/reorganize the indexes that need it, but also give you the time that it started and ended.

    Accepted Solution


    I want to rebuild selected indexes. I have the list.
    LVL 75

    Expert Comment

    by:Anthony Perkins
    Then it sounds like you are on the right track.

    Author Closing Comment

    My idealogy and the approach mentioned in the Question is absolutely correct and also accepted by one of the Expert.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
    JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now