Find out the SQL Server restart date/time with TSQL

  • Hi,

    I am just wondering if there is way to figure out when SQL Server was last restarted using TSQL?

    Thanks.

  • There are a bunch of system processes that are started when SQL Server starts. The time that these processes start is effectively the time that SQL Server started.

    With the above explanation, the following gives you your answer

    select MIN(login_time) from sys.sysprocesses

  • Another way is to check when the tempdb is created..

    PS: Tempdb is recreated whenever the server is started..

    select create_Date from sys.databases

    where name = 'tempdb'

    One more point, Tempdb is created before the services start, hence we will get a earlier time .

    Kindest Regards,
    Paarthasarathy
    Microsoft Certified Technology Specialist
    http://paarthasarathyk.blogspot.com

  • A few days ago there was a nice article about this subject

    http://www.sqlservercentral.com/scripts/GETDATE()/69319/

    Regards,

    Marco

  • If your SQL Server is 2005 or later, you can use:

    SELECT 'Statistics since: ' + CAST(sqlserver_start_time AS VARCHAR) FROM sys.dm_os_sys_info

    It's more safe and reliable.

  • fdassis (12/23/2012)


    If your SQL Server is 2005 or later, you can use:

    SELECT 'Statistics since: ' + CAST(sqlserver_start_time AS VARCHAR) FROM sys.dm_os_sys_info

    It's more safe and reliable.

    Not so much a case of reliability than accuracy. The first entry is start up (in dm_os_sys_info). This is followed by system process starting followed by tempdb creation.

    SELECT 'OS Info - SQL Start' AS Process, sqlserver_start_time AS Time FROM sys.dm_os_sys_info

    UNION ALL

    SELECT 'System Process Start', MIN(login_time) FROM sys.sysprocesses

    UNION ALL

    SELECT 'TempDB Created', create_date FROM sys.databases WHERE name = 'tempdb'

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

  • Starts in 2008, not 2005. dm_os_sys_info.sqlserver_start_date started only in 2008.

Viewing 7 posts - 1 through 6 (of 6 total)

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