Technical Conventions

@Databases — Database Selection

Select databases using keywords, wildcards, and exclusions. The hyphen character (-) excludes databases, the percent character (%) is a wildcard, and the comma (,) combines operations. Defaults to USER_DATABASES when NULL.

ValueDescription
USER_DATABASESAll user databases (default when NULL)
SYSTEM_DATABASESAll system databases (master, msdb, model)
ALL_DATABASESAll databases
AVAILABILITY_GROUP_DATABASESAll databases in availability groups
Db1The database Db1
Db1, Db2The databases Db1 and Db2
%pattern%All databases matching the pattern
USER_DATABASES, -Db1All user databases except Db1
USER_DATABASES, -%test%All user databases excluding names matching %test%
ALL_DATABASES, -%Db%All databases that do not match the pattern
USER_DATABASES, -AVAILABILITY_GROUP_DATABASESAll user databases that are not in availability groups

All procs that accept @Databases use the shared function optimize.fn_GetDatabases for consistent parsing.

@RunnableUnder Parsing

Every proc that accepts @RunnableUnder uses the same parsing pattern:

DECLARE @ThresholdStd DECIMAL(10,2) = NULL;
DECLARE @ThresholdEnt DECIMAL(10,2) = NULL;
DECLARE @ActiveThreshold DECIMAL(10,2) = NULL;

IF @RunnableUnder IS NOT NULL AND LTRIM(RTRIM(@RunnableUnder)) <> ''
BEGIN
    IF @RunnableUnder LIKE '%,%e'
    BEGIN
        SET @ThresholdStd = TRY_CAST(LEFT(@RunnableUnder, CHARINDEX(',', @RunnableUnder) - 1) AS DECIMAL(10,2));
        SET @ThresholdEnt = TRY_CAST(SUBSTRING(@RunnableUnder, CHARINDEX(',', @RunnableUnder) + 1,
            LEN(@RunnableUnder) - CHARINDEX(',', @RunnableUnder) - 1) AS DECIMAL(10,2));
    END
    ELSE
    BEGIN
        SET @ThresholdStd = TRY_CAST(@RunnableUnder AS DECIMAL(10,2));
        SET @ThresholdEnt = @ThresholdStd;
    END
END

SET @ActiveThreshold = CASE WHEN @IsEnterprise = 1 THEN @ThresholdEnt ELSE @ThresholdStd END;

@LinkedServer Post-Processing

When @LinkedServer = 1, the orchestrator's combined output is post-processed line-by-line:

Enterprise Detection

Used for: WITH (ONLINE = ON) on index operations, and the Enterprise threshold in @RunnableUnder.

IF CAST(SERVERPROPERTY('Edition') AS NVARCHAR(500)) LIKE '%Enterprise%'
    OR CAST(SERVERPROPERTY('Edition') AS NVARCHAR(500)) LIKE '%Developer%'
    SET @IsEnterprise = 1;