SQL Process % Complete

  • If you wanted to find out (SQL Server 2005 and onwards or with compatibility modes of 90 and higher) how long a particular Backup or restore on a database was taking or elapsed time, then the following SQL can help:

    (I know the SQL GUI will show this in increments of 10% and all... but sometimes we just want to know how long it has taken and what percent it is currently at 😀 )

    USE MASTER

    --

    SELECT SESSION_ID, '[' + CAST(DATABASE_ID AS VARCHAR(10)) + '] ' + DB_NAME(DATABASE_ID) AS [DATABASE],

    PERCENT_COMPLETE, START_TIME, STATUS, COMMAND,

    DATEADD(MS, ESTIMATED_COMPLETION_TIME, GETDATE()) AS ESTIMATED_COMPLETION_TIME, CPU_TIME

    FROM SYS.DM_EXEC_REQUESTS

    --Apply this Where Clause Filter if you need to check specific events such as Backups, Restores, Index et al.

    WHERE COMMAND LIKE '%BACKUP%' OR COMMAND LIKE '%RESTORE%' OR COMMAND LIKE '%INDEX%' OR COMMAND LIKE '%DBCC%'

    Mehernosh

    Mehernosh.

  • Nice, thank you.

    You could add it to the scripts section, using the contribution center.

    -- Gianluca Sartori

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply