Technical Article

SQL Server instance startup type check by SQL script

,

I have developed the script to check SQL Server instances startup type, sometimes we didn't know all our SQL instances startup type correctly configurated, especially we cannot distinguish the Automatic and Automatic(Delayed Start) from the direct query, the only way is querying from the registry, you can use this script in your environment to bulk check.

the sample output:

-- 2021-12-24, Developed by Vincent Jiang.

SET NOCOUNT ON;

DECLARE @SQLServerStartupMode1 [int],
        @SQLServerStartupMode2 [int],
        @SQLServerStartupType [char] (256),
        @SQLServerRegistryKeyPath [varchar] (256)


IF SERVERPROPERTY('InstanceName') IS NULL -- Default Instance
BEGIN --default instance
    SET @SQLServerRegistryKeyPath = 'SYSTEMCurrentControlSETSERVICESMSSQLSERVER'
END
ELSE
BEGIN --Named Instance
    SET @SQLServerRegistryKeyPath = 'SYSTEMCurrentControlSETSERVICESMSSQL$' + CAST(SERVERPROPERTY('InstanceName') AS [sysname])

END
 
EXEC [master]..[xp_regread] 'HKEY_LOCAL_MACHINE'
    ,@SQLServerRegistryKeyPath
    ,@value_name = 'DelayedAutostart'
    ,@value = @SQLServerStartupMode1 OUTPUT
 
EXEC [master]..[xp_regread] 'HKEY_LOCAL_MACHINE'
    ,@SQLServerRegistryKeyPath
    ,@value_name = 'Start'
    ,@value = @SQLServerStartupMode2 OUTPUT
 

SET @SQLServerStartupType = (
        SELECT 'Start Up Mode' = CASE
                WHEN @SQLServerStartupMode1 = 1 and @SQLServerStartupMode2 = 2
                    THEN 'Automatic(Delayed Start)'
                WHEN @SQLServerStartupMode1 = 0 and @SQLServerStartupMode2 = 2
                    THEN 'Automatic'
                WHEN @SQLServerStartupMode2 = 2
                    THEN 'Automatic'
                WHEN @SQLServerStartupMode2 = 3
                    THEN 'Manual'
                WHEN @SQLServerStartupMode2 = 4
                    THEN 'Disabled'
                END
        )

 
SELECT @SQLServerStartupType AS SQLServerStartupType

Rate

5 (1)

You rated this post out of 5. Change rating

Share

Share

Rate

5 (1)

You rated this post out of 5. Change rating